CLLocationCoordinate2D
我在import random
sentence = input("Enter the sentence: ")
sentence=sentence.lower()
languages=[['hello','goodbye','thank you',"you\'re welcome",'have','a','nice','day','how','are','you'],
['ola','Tehau','obrigado','seja bem-vindo','ter','uma','bom','dia','como','esta','voce'],
['hello','faida','Asante','karibu','kuwa na','a','nzuri','siku','vipi','ni','wewe'],
['hallo','Vaarwel','dank je','graag gedaan','habben','een','leuk','dag','hoe','ziin','u'],
['hola','adios','gracias','De nada','tener','un','bonito','dia','como','son','tu']]
t=''
if sentence == "have a nice day":
words=sentence.split()
for word in words:
i=languages[0].index(word)
r=random.randint(1,4)
t+=languages[r][i]+' '
elif sentence == "goodbye":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence == "hello":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence == "you're welcome":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence== "thank you":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence== "how are you":
words=sentence.split()
for word in words:
i=languages[0].index(word)
r=random.randint(1,4)
t+=languages[r][i]+' '
print("The translated sentence is",t)
上收到了此错误:
sentence=input("Enter the sentence")
答案 0 :(得分:1)
此错误是由使用Python 2执行Python 3代码引起的。
使用Python 3执行程序时,您的程序运行正常。只需使用python3
命令运行它:
python3 you_code.py
print()
的括号:if sentence == "have a nice day":
input()
替换为raw_input()
:sentence = raw_input("Enter the sentence: ")
这给出了这个Python 2程序:
import random
sentence = raw_input("Enter the sentence: ")
sentence=sentence.lower()
languages=[['hello','goodbye','thank you',"you\'re welcome",'have','a','nice','day','how','are','you'],
['ola','Tehau','obrigado','seja bem-vindo','ter','uma','bom','dia','como','esta','voce'],
['hello','faida','Asante','karibu','kuwa na','a','nzuri','siku','vipi','ni','wewe'],
['hallo','Vaarwel','dank je','graag gedaan','habben','een','leuk','dag','hoe','ziin','u'],
['hola','adios','gracias','De nada','tener','un','bonito','dia','como','son','tu']]
t=''
if sentence == "have a nice day":
words=sentence.split()
for word in words:
i=languages[0].index(word)
r=random.randint(1,4)
t+=languages[r][i]+' '
elif sentence == "goodbye":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence == "hello":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence == "you're welcome":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence== "thank you":
i=languages[0].index(sentence)
r=random.randint(1,4)
t+=languages[r][i]
elif sentence== "how are you":
words=sentence.split()
for word in words:
i=languages[0].index(word)
r=random.randint(1,4)
t+=languages[r][i]+' '
print "The translated sentence is", t