这是我的程序:
import os
system=1
google=["search web","google search","help","google","open google","search google"]
while system==1:
action=(input("What would you want me to do for you : "))
googlesearch=("opera https://www.google.com/#q=")
if any(word in action for word in google):
actiongoogle=(input("What do you want me to google?: "))
if actiongoogle=="nothing":
print("Ok Then.")
else:
print("launching google");os.system(googlesearch+actiongoogle)
当输入只有1个单词时程序正常运行,但是当你留下一些空格时,它会打开新标签,而且它没有使用www.google.com ...
答案 0 :(得分:0)
您需要使用' +'
替换字词之间的空格
import os
system=1
google=["search web","google search","help","google","open google","search google"]
while system==1:
action=(input("What would you want me to do for you : "))
googlesearch=("google-chrome https://www.google.com/#q=")
if any(word in action for word in google):
actiongoogle=(input("What do you want me to google?: "))
if actiongoogle=="nothing":
print("Ok Then.")
else:
print("launching google");
s_s="+".join(actiongoogle.split())
ls = s_s.replace(' ','+')
os.system(googlesearch+ls)