请给我回答 - 这段代码有什么不对吗?我没有看到任何单词" ok" (然后' vvod' =' zagadkaa')
import random
zagadka = [1,2,3]
random.shuffle(zagadka)
print ("Please enter number between 1 and 3")
zagadkaa = zagadka.pop()
vvod = input("Enter number here")
if vvod == zagadkaa:
print ("ok")
else:
print ("wrong %d"%zagadkaa)
print ("Goodbye")
然后我运行这个脚本我看到了:
Please enter number between 1 and 3
Enter number here1
wrong 1
Goodbye
Process finished with exit code 0
答案 0 :(得分:0)
也许你应该用raw_input()替换input()。这是输入函数的文档
input([prompt])
Equivalent to eval(raw_input(prompt)).
This function does not catch user errors. If the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation.
If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.
Consider using the raw_input() function for general input from users.
答案 1 :(得分:0)
试试这个:
import random
zagadka = [1,2,3]
random.shuffle(zagadka)
print ("Please enter number between 1 and 3")
zagadkaa = zagadka.pop()
vvod = int(raw_input("Enter number here")) # make sure we have a number, not a string, and don't eval it.
if vvod == zagadkaa:
print ("ok")
else:
print ("wrong %d"%zagadkaa)
print ("Goodbye")