我正在编写一个语法游戏(Python),但它不起作用。我如何解决它? 代码:
print("Welcome! Type in 'Enter' (without apostrophes) to begin")
start = input
if start == "Enter":
print "Fill in the blanks: I __ a boy"
answer = input
if answer != "am":
print "Wrong answer! Try again: I __ a boy"
if answer == "am":
print "Congratulations!"
它返回:
Welcome! Type in 'Enter' (without apostrophes) to begin
Wrong answer! Try again: I __ a boy
答案 0 :(得分:2)
您实际上没有从用户那里获得任何输入,当您编写start = input
时,您将变量start设置为等于内置函数输入。要真正获得输入,您需要使用start = input(prompt)
,如here所示。
start = input("Welcome! Type in 'Enter' (without apostrophes) to begin")
if start == "Enter":
answer = input("Fill in the blanks: I __ a boy")
if answer != "am":
print "Wrong answer! Try again: I __ a boy"
elif answer == "am":
print "Congratulations!"