带有变量作为条件的if语句,变量可以有多种可能性

时间:2017-10-23 20:20:01

标签: python-3.x

print("Welcome to your phones Troubleshooter")
issue = input(str("Does your phone have an issue?"))
if [issue == "yes", "Yes", "YES"]:

我已经设置了三个选项的参数,但它似乎没有工作它只是继续我的其他声明。我该怎么办?

2 个答案:

答案 0 :(得分:0)

你可以这样做:

print("Welcome to your phones Troubleshooter")
issue = input(str("Does your phone have an issue?"))
if issue.lower() == "yes":
  print("There is an issue")   

或代码中的稍微更改if语句:

 print("Welcome to your phones Troubleshooter")
 issue = input(str("Does your phone have an issue?"))
 if issue == "yes" or issue == "Yes" or issue == "YES":
      print("There is an issue")

您应该阅读if-statement语法。你做错了。

答案 1 :(得分:0)

print("Welcome to your phones Troubleshooter")
issue = input(str("Does your phone have an issue?"))

accepted_string = {"yes", "Yes", "YES"}

if issue in accepted_string:
  print("Found it")
else:
  print("Not found")