有一些小程序要求输入 char - y,b,s,然后通过比较来检查输入是什么。
我运行程序时遇到的问题是-
NameError:未定义名称“b”
如果输入是,比如说,b。
这是我的代码:
print("Please think of a number between 1 and 7")
print("Is it 4? (y,s,b)")
answer=char(input())
if (answer=='y'):
print("It is Four!")
elif (answer=='s'):
print("Is it 2? (y,s,b)")
answer=input()
if (answer=='y'):
print("It is two!")
elif (answer=='s'):
print("It is one!")
elif (answer=='b'):
print("It is Three!")
elif (answer=='b'):
print("Is it 6? (y,s,b)")
answer=input()
if (answer=='y'):
print("It is Six!")
elif (answer=='s'):
print("It is Five!")
elif (answer=='b'):
print("It is Seven!")