Python 我不明白,什么';我的代码怎么了?
我不明白,我的代码怎么了?每当我键入Python 我不明白,什么';我的代码怎么了?,python,Python,我不明白,我的代码怎么了?每当我键入hey、hi或sup,它都不会显示我在代码中写的内容,而是显示其他内容-我犯了什么错误 这是我的密码: import os import random import time for i in range(1, 2): a = random.choice(("hi, sir", "hey, sir", "hello, sir", "sup, sir", "Joe Reporting, Sir")) print(a) os.syste
hey
、hi
或sup
,它都不会显示我在代码中写的内容,而是显示其他内容-我犯了什么错误
这是我的密码:
import os
import random
import time
for i in range(1, 2):
a = random.choice(("hi, sir", "hey, sir", "hello, sir", "sup, sir", "Joe Reporting, Sir"))
print(a)
os.system("say '"+a+"'")
res1 = input()
if res1 is ("hi", "hey", "hello", "sup", "Hey Joe"):
GE = ("I am Joe, Your New Personal Assintant. Nice to meet you.")
print(GE)
os.system("say '"+GE+"'")
else:
js = random.choice(("okay, what would you like to do", "So, Sir What Would you like to do ", "So Sir, What to do", "k, what are we going to do"))
print(js)
os.system("say '"+js+"'")
User_inp = input()
print("Ok, searching")
'''
if inp "?":
print("Um...Let me Search")
'''
Next_inp = input()
g = random.choice(("Searching, sir", "I am on it."))
print(g)
正如评论中提到的,您必须像这样修改代码
res1 = input()
if res1 in ("hi", "hey", "hello", "sup", "Hey Joe"):
GE = ("I am Joe, Your New Personal Assintant. Nice to meet you.")
print(GE)
os.system("say '" + GE + "'")
您混淆了
在
中的作用和是
;因此,在初始代码中使用中的更改是
可以解决您的问题。在
中,而不是在
中。查找如何检查python中列表或元组中的值^this for the line'if res1 is(“…):”,it's'in'not'is in'。。i、 e如果res1在('hi','hey'):@LukeK实际上在中,而不是在中,谢谢khelwood。在跳进去之前,我应该看看自己是怎么做的!