【发布时间】:2021-12-29 06:35:25
【问题描述】:
在下面的代码中,if 语句到达并运行良好。然而,elif 声明似乎没有任何效果。当脚本运行时,当满足elif 语句的条件时,什么也没有发生,当我按两次返回按钮时,脚本只是继续跳过elif 语句。
我的代码:
print("If you want to name this window press 1, if you want to describe it press 2")
if input() == "1":
print("Please enter this window's title:")
current_window_title = input()
print("Do you also want to describe this window? P.S: You can do this later.)")
if input().lower() == "yes":
print("Please enter this window's description:")
current_window_description = input()
else:
current_window_description = "None"
elif input() == "2":
print("Please enter this window's description:")
current_window_description = input()
print("Do you also want to give this window a title? P.S: You can do this later.")
if input().lower() == "yes":
print("Please enter this window's title:")
current_window_title = input()
【问题讨论】:
-
您要求它输入两个不同的时间。对
input()的每次调用都希望您输入一个单独的号码。你需要写value = input()。然后if value == "1"和if value == "2"所以它不会尝试重新输入第二个数字。 -
elif表示else if,因此只有在前面的if条件为False时才会评估它 - 您是否首先输入了'1'以外的其他内容,然后 那么'2'?但是,您可能希望将输入存储在变量中并在if .. elif ..语句中使用它 -
@FrankYellin 这很有意义并且有效,谢谢!
标签: python if-statement input user-input