如果选择== 1:在def mainmenu()下我得到这个无效语法:不明白为什么我收到此错误。请帮我解决这个问题。我完全没有理由为什么它在那里。 contacts = {}
class person:
def ___init__(self,first,last,number):
self.first = first
self.last = last
self.number = number
def get_info(self):
print(first,last,number)
class friend(person):
def __init__(self,email,bday):
self.email = email
self.bday = bday
def get_info_friend(self):
super().get_info()
print(email,bday)
def add_a_contact():
choice = int(input("Contact type: \n\t 2: Person \nEnter an option here:"))
first = input("Enter the first name:")
last = input("Enter the last name:")
number = input("Enther the number:")
if choice == 1:
email = input("Email Address is:")
bday = input("Their bday is:")
return Friend(email,bday,first,last,number)
return person(first,last,number)
def add_contact_to_dict():
contact = add_a_contact()
contacts[contact.last_name] = contact
def lookup():
last = input("What is their last name?:")
if last in contacts:
contact = contacts[last]
print("Name&number: ", contact.first,contact.last,contact.number)
if type(friend) is friend:
print("Email and Bday is: ", contact.email,contact.bday)
def mainmenu():
selection = 0
temp = ""
while selection != 3:
print("Select an option: \n\t 1: Add \n\t 2: Lookup \n\t 3: Exit")
selection = int(input("Enter an option:")
if selection == 1:
temp = add_contact_to_dict()
elif selection == 2:
lookup()
elif selection == 3:
pass
else:
print("Not a valid option")
if __name__ == "__mainmenu__":
mainmenu()
答案 0 :(得分:0)
因此,当您被要求输入选择时,您需要另一个括号来表示“int”部分。希望这可以解决您的问题。