country = input("Please enter a country: ")
if country == United Kingdom:
print("Accents in the United Kingdom change noticeably about every 40km.")
elif country == Italy:
print("Italy has three active volcanoes: Vesuvius, Etna, and Stromboli.")
elif country == France:
print("France is the world's most popular tourist destination.")
elif country == Germany:
print("One-third of Germany is still covered in forests and woodlands.")
elif country == Japan:
print("In Japanese, the name Japan is Nihon or Nippon, which means Land of the Rising Sun.")
elif country == USA:
print("100 acres of pizza are served in the United States every day!")
elif country == Canada:
print("The Royal Montreal Golf Club is the oldest golf club in North America.")
else:
print(country + " is currently not a G7 country")
我一直收到语法错误,但似乎找不到我的错误。 我的错误是: 追溯(最近一次通话): 文件“ python”,第3行 如果国家==英国: ^ SyntaxError:语法无效
答案 0 :(得分:1)
您需要在字符串值两边加上引号。
if country == 'United Kingdom':
答案 1 :(得分:1)
每个“ ==”之后的问题,语法不正确,请尝试在每个国家/地区添加引号
country = str(input("Please enter a country: "))
if country == "United Kingdom":
print("Accents in the United Kingdom change noticeably about every 40km.")
elif country == "Italy":
print("Italy has three active volcanoes: Vesuvius, Etna, and Stromboli.")
elif country == "France":
print("France is the world's most popular tourist destination.")
elif country == "Germany":
print("One-third of Germany is still covered in forests and woodlands.")
elif country == "Japan":
print("In Japanese, the name Japan is Nihon or Nippon, which means Land of the Rising Sun.")
elif country == "USA":
print("100 acres of pizza are served in the United States every day!")
elif country == "Canada":
print("The Royal Montreal Golf Club is the oldest golf club in North America.")
else:
print(country + " is currently not a G7 country")