如果word_pick不是==random_choice怎么办?

How do I do if word_pick not == random_choice?

import random
import time
import sys

from colored import fg

color1 = fg("red")
color2 = fg("blue")
color3 = fg("green")
color4 = fg("yellow")


for x in (color1 + "Hi,\nThis is a word guessing game, you will have to guess the answer from 100 words.\nYou will have 45 chances to guess the number. You initially start with 225 points. Every chance you enter the wrong answer, you lose 5 points. The quicker you guess, the higher your score(225 is the highest score you can have).\n\n"):
    sys.stdout.write(x)
    sys.stdout.flush()
    time.sleep(0.03)

words = ['time', 'year', 'people', 'way', 'day', 'man', 'thing', 'woman', 'life', 'child', 'world', 'school', 'state', 'family', 'student', 'group', 'country', 'problem', 'hand', 'part', 'place', 'case', 'week', 'company', 'system', 'program', 'question', 'work', 'government', 'number', 'night', 'point', 'home', 'water', 'room', 'mother', 'area', 'money', 'story', 'fact', 'month', 'lot', 'right', 'study', 'book', 'eye', 'job', 'word', 'business', 'issue', 'side', 'kind', 'head', 'house', 'service', 'friend', 'father', 'power', 'hour', 'game', 'line', 'end', 'member', 'law', 'car', 'city', 'community', 'name', 'president', 'team', 'minute', 'idea', 'kid', 'body', 'information', 'back', 'parent', 'face', 'others', 'level', 'office', 'door', 'health', 'person', 'art', 'war', 'history', 'party', 'result', 'change', 'morning', 'reason', 'research', 'girl', 'guy', 'moment', 'air', 'teacher', 'force', 'education']


for x in (color2+ f"These are the words in the list you can pick from:\n\n{color3}'time', 'year', 'people', 'way', 'day', 'man', 'thing', 'woman', 'life', 'child', 'world', 'school', 'state', 'family', 'student', 'group', 'country', 'problem', 'hand', 'part', 'place', 'case', 'week', 'company', 'system', 'program', 'question', 'work', 'government', 'number', 'night', 'point', 'home', 'water', 'room', 'mother', 'area', 'money', 'story', 'fact', 'month', 'lot', 'right', 'study', 'book', 'eye', 'job', 'word', 'business', 'issue', 'side', 'kind', 'head', 'house', 'service', 'friend', 'father', 'power', 'hour', 'game', 'line', 'end', 'member', 'law', 'car', 'city', 'community', 'name', 'president', 'team', 'minute', 'idea', 'kid', 'body', 'information', 'back', 'parent', 'face', 'others', 'level', 'office', 'door', 'health', 'person', 'art', 'war', 'history', 'party', 'result', 'change', 'morning', 'reason', 'research', 'girl', 'guy', 'moment', 'air', 'teacher', 'force', 'education' \n\n\n"):
    sys.stdout.write(x)
    sys.stdout.flush()
    time.sleep(0.01)

time.sleep(2)

word_pick = input(color4 + "Pick a random word from the above list: ")

random_choice = random.choice(words)

chances = 45
score = 225

if word_pick.upper() or word_pick.lower() or word_pick.title() not random_choice:
    print("Congrats, you have picked the right word.")

if word_pick.upper() or word_pick.lower() or word_pick.title() == random_choice:
    print("Congrats, you have picked the right word.")

我说的是第一个if语句,我怎么不== random_choice ??? 所以如果 word_pick 不在 random_choice 中,我想做,然后将分数减去 5

PLZ 帮助

使用 !=

if word_pick.upper() or word_pick.lower() or word_pick.title() != random_choice:
    print("Congrats, you have picked the right word.")
    score = score - 5

在此处阅读更多内容: https://docs.python.org/3/library/stdtypes.html#comparisons

我建议要么只检查单词的小写版本,要么严格检查。

PENALTY = 5
if word_pick.lower() == random_choice:
    # guess is right
    print("Congrats")
else:
    # guess isn't right
    print("You have failed")
    score -= PENALTY

如果要单独测试所有可能的版本,可以将它们放入列表中并使用 in 运算符。

if random_choice in [word_pick.lower(), word_pick.upper(), word_pick.title()]:
    # guess is right