我正在制作一个脚本,您可以根据该脚本的报价来猜测电影。我想知道的是如何做到这一点,以便我可以使用“终结者”和“终结者”,并允许拼写错误仍然正确。
我试图查找它,但什么也没发现。
#Guess that movie, gives a quote and you have to guess it for points, add a high score system.
from random import randint
points = 0
quote1 = randint(0,3)
quote2 = randint(0,3)
quote3 = randint(0,3)
quote4 = randint(0,3)
movieQuoteEasy = ["You're going to need a bigger boat.", "I'll be back.", "Here's Johnny!", "Say hello to my little friend!"]
movieQuoteMedi = ["Luca Brazi Sleeps with the fishes.", "Whatever doesn't kill you simply makes you... stranger.", "You talking to me?", "I love the smell of Napalm in the morning."]
movieQuoteHard = ["Rosebud...", "How am I funny to you? what makes me so funny.", "They call it a Royal with Cheese.", "Go ahead, make my day."]
movieQuoteExtr = ["I tried... at least I did that.", "Gentlemen, you can't fight here this is the way room!", "I'm having an old friend for Dinner.", "The greatest trick the devil pulled was convincing the world he didn't exist."]
movieAnswerEasy = ["Jaws", "The Terminator", "The Shining", "Scarface"]
movieAnswerMedi = ["The Godfather", "The Dark Knight", "Taxi Driver", "Apocalypse Now"]
movieAnswerHard = ["Casablanca", "Goodfellas", "Pulp Fiction", "Dirty Hary"]
movieAnswerExtr = ["One Flew Over the Cuckos Nest", 'Dr. Strangelove', "Silence of the Lambs", "The Usual Suspects"]
print("Welcome to Guess That Movie!")
input()
#Easy Question
print("Easy: " + movieQuoteEasy[quote1])
guess1 = input()
#Takes the value for use input and checks it against the correct answer.
if guess1 == movieAnswerEasy[quote1]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerEasy[quote1])
#Medium Question
print("Medium: " + movieQuoteMedi[quote2])
guess2 = input()
#Takes the value for use input and checks it against the correct answer.
if guess2 == movieAnswerMedi[quote2]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerMedi[quote1])
#Hard Question
print("Hard: " + movieQuoteHard[quote3])
guess3 = input()
#Takes the value for use input and checks it against the correct answer.
if guess3 == movieAnswerHard[quote3]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerHard[quote3])
#Extream Question
print("Insane: " + movieQuoteExtr[quote4])
guess4 = input()
# Takes the value for use input and checks it against the correct answer.
if guess4 == movieAnswerExtr[quote4]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerExtr[quote4])
print("\nGreat job, you have " + str(points) + " points.")
input()
exit()
我希望能够使用“终结者”而只是“终结者”
答案 0 :(得分:1)
我知道如何解决您的问题。您可以做的第一件事是在输入的末尾添加.lower()
。这会将所有字母以小写形式显示在用户输入中。像这样:guess1 = input().lower
。现在,用户键入大写还是小写都没有关系。也;您应该这样做:
guess1 = input(">>> ").lower() #Allows the user to input lower case letters.
if "terminator" in guess1: #This is probably what you are looking for.
#If the program detects the keyword 'terminator'
#in your guess, then the if statement will execute.
#Whatever happens when the user is correct.
else:
#Whatever happens when the user is incorrect.
希望我能帮助您!