Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我不明白,什么';我的代码怎么了?_Python - Fatal编程技术网

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。在跳进去之前,我应该看看自己是怎么做的!