我在Windows 8.1中使用Python 3.5.0并且我正在尝试制作一个猜测您的动物的程序,而且我不知道如何告诉计算机记录特定的键以询问下一个问题让我们#39 ; s说我想按Y键是的,程序说错误,因为它不知道Y键以及如何处理它。
print('Hello, do you want to play a game')
print('Great lets play a guessing game')
print('Think of an animal and I will ask you different questions and I will try to guess your animal')
print('Question #1 Can your animal fly Press Y for yes and N for no')
input(N):
print('You picked no')
The error is "invalid Syntax This a screenshot of my problem .jpg
答案 0 :(得分:0)
您正在以错误的方式使用input()
功能。
查看python input([prompt])
函数doc:
如果存在prompt参数,则将其写入标准输出 没有尾随换行符。然后该函数从输入中读取一行, 将其转换为字符串(剥离尾随换行符),然后返回 那。读取EOF时,会引发EOFError。
这么说并且看着你要实现的目标,你可以:
print()
函数这是您的代码应该如何实现您的目标:
print('Hello, do you want to play a game')
print('Great lets play a guessing game')
print('Think of an animal and I will ask you different questions and I will try to guess your animal')
fly = input('Question #1 Can your animal fly? (Press Y for yes and N for no)')
if fly == 'N':
print('You picked no')
elif fly == 'Y':
print('You picked yes')