我一直想弄清楚我在这里做错了什么,我只是不明白。 Python说第22行有语法错误,但我不知道它有什么问题...请帮忙。这是另一个程序的一部分,但这个有问题。
# Destinations Module
# -------------------
# This module provides information about European destinations and rates
# All rates are in euros
def print_options():
# Print travel options
print("Travel Options")
print("--------------")
print("1. Rome")
print("2. Berlin")
print("3. Vienna")
print("")
def get_choice():
# Get destination choice
while True:
try:
choice = int(input("Where would you like to go? ")
if (choice < 1 or choice > 3):
print("Please select a choice between 1 and 3.")
continue
except ValueError:
print("The value you entered is invalid. Only numerical values are valid.)
else:
return choice
def get_info(choice):
# Use numeric choice to look up destination info
# Rates are listed in euros per day
# Choice 1: Rome at €45/day
if (choice == 1)
return "Rome", 45
# Choice 2: Berlin at €18/day
elif (choice == 2)
return "Berlin", 18
# Choice 3: Vienna, €34/day
elif (choice == 3)
return "Vienna", 34
答案 0 :(得分:0)
您的代码中存在多个错误。在代码中检查这个正确的版本和我的评论:
#!/usr/bin/python
# -*- coding: utf-8 -*-
def print_options():
# Print travel options
print("Travel Options")
print("--------------")
print("1. Rome")
print("2. Berlin")
print("3. Vienna")
print("")
def get_choice():
# Get destination choice
while True:
try:
# here you need a right bracket
choice = int(input("Where would you like to go? "))
# here you can put each condition into its own block
if (choice < 1) or (choice > 3):
#here you need some identation
print("Please select a choice between 1 and 3.")
continue
except ValueError:
# here you have to put the whole string into ""
print("The value you entered is invalid. Only numerical values are valid.")
else:
return choice
def get_info(choice):
# Use numeric choice to look up destination info
# Rates are listed in euros per day
# Choice 1: Rome at €45/day
# here you have to add a colon after every if statement
if (choice == 1):
return "Rome", 45
# Choice 2: Berlin at €18/day
elif (choice == 2):
return "Berlin", 18
# Choice 3: Vienna, €34/day
elif (choice == 3):
return "Vienna", 34