elif块未在Python中执行
这里怎么了?输入3(=5: 如果答案=‘是’: 打印“太棒了,我要出去!” 打印“你愿意和我一起去吗?” 其他: 打印“太棒了,我现在要出去了!”elif块未在Python中执行,python,if-statement,Python,If Statement,这里怎么了?输入3(=5: 如果答案=‘是’: 打印“太棒了,我要出去!” 打印“你愿意和我一起去吗?” 其他: 打印“太棒了,我现在要出去了!” elif weatherraw\u input返回的字符串不是整数,例如'3'而不是3 在Python 2中,字符串的比较总是大于整数,因此weather>=5始终为真 要解决此问题,请将天气转换为整数: weather = int(raw_input('How is the weather today, from 0 to 10? ')) 原始输
elif weather
raw\u input
返回的字符串不是整数,例如'3'
而不是3
在Python 2中,字符串的比较总是大于整数,因此weather>=5
始终为真
要解决此问题,请将天气
转换为整数:
weather = int(raw_input('How is the weather today, from 0 to 10? '))
原始输入返回一个字符串,您需要将其转换为整数
weather = int(raw_input('How is the weather today, from 0 to 10? '))
您需要捕获处理错误输入的任何异常。
raw\u input
返回一个字符串-您正在将字符串与条件语句中的整数进行比较。
weather = int(raw_input('How is the weather today, from 0 to 10? '))