Python无法识别if - Statement

时间:2018-02-16 10:52:07

标签: python python-3.x if-statement input

我是Coding的新手,我从Python开始学习如何编码。 我打算编写一个简单的测验,用户选择他们想要玩的测验。 我做了输入()但它没有转到if - Statement。 代码:

import quiz1
import quiz2
import quiz3
import quiz4

quiz = input("Please choose which Quiz you want to play (1-4): ")
print(quiz)

if quiz == 1:
        quiz1
        #f1 = open(fragebogen1.py)
        #print(f1)
elif quiz == 2:
        print("hello")
elif quiz == 3:
        print("hello")
elif quiz == 4:
        print("hello")

提前致谢

3 个答案:

答案 0 :(得分:3)

quiz = int(input("Please choose which Quiz you want to play (1-4): ")) 函数返回一个字符串。您需要将用户的输入转换为整数:

if int(quiz) == 1:

答案 1 :(得分:3)

在检查之前将输入转换为整数

insert into table_xml -- this table has xmlindex, here i dont want to use xmlindex

select * from some_other_table;
-----------------------------------------------
select * from table_xml, xmltable (...); -- here xmlindex is giving great performance

答案 2 :(得分:-1)

无法联系到elif == 1,因为您输入了if quiz == 1。 相反,您需要输入elif quiz == 2: