-2

I'm writing this program that lets users choose an option to display, change,add, remove, write or quit I keep getting invalid syntax error on this elif statement in my program and i dont know why?

DISPLAY = 'D'
CHANGE = 'C'
ADD = 'A'
REMOVE = 'R'
WRITE = 'W'
QUIT = 'Q'

#main function
def main ():
    print()
    print()
    print('\t Wombat Valley Tennis Club')
    print('\t   Member Register')
    print('\t   =======================')
    main_dic = {}
    with open ('wvtc_data.txt','r')as x:
          for line in x:
                line = line.rstrip ('\n')
                items = line.split (':')
                key,value = items[0], items[1:]
                main_dic[key] = values
                choice = input('choice: ')
                while choice != QUIT:
                      choice = get_menu_choice()
                      if choice==DISPLAY:
                            display(main_dic)
                            elif choice==CHANGE:
                                  change(main_dic)
                                  elif choice== REMOVE:
                                        remove (main_dic)
                                        elif choice==WRITE:
                                              write(main_dic)

def get_menu_choice():
      print()
      print("\t\t Main Menu")
      print()
      print('\t<D>isplay member details')
      print('\t<C>hange member details')
      print('\t<A>dd a new member')
      print('\t<R>emove a member')
      print('\t<W>rite updated details to file')
      print('\t<Q>uit')
      print()
      print('Your choice (D, C, A, R, W OR Q)?\t[Note: Only Uppercase]')
      print()
      choice = input("Enter your choice: ")
      while choice < DISPLAY and choice < CHANGE or choice > QUIT:
            choice = input ('Enter your choice: ')
            return choice
def display(main_dic):
      name = input('Type the name of the member:')
      print()
      print (main_dic.get(name, 'not found!'))
      print()
      print()

def change(main_dic):
      name=input("Enter the member number")
      print()
      print(main_dic.get(name,'not found!'))
      print()
      NAME = 1
      EMAIL = 2
      PHONE = 3
      print('Please select')
      print('==============')
      print('Change Name<1>')
      print('Change E-mail<2>')
      print('Change Phone Number<3>')
      print()
      if choose == NAME:
            new_name = input('Enter the name: ')
            print()
            print("Data has been changed")
            main_dic[name][0]=new_name
            print (mem_info[name])
            print()
            elif choose == EMAIL:
                  new_email=input('Enter the new email address:')
                  print ('Email address has been changed')

                  #change the data
                  main_dic[name][1]=new_email
                  print(mem_info[name])
                  print()
                  elif choose == PHONE:
                        new_phone = int (input('Enter the new phone number'))
                        print ("phone number has been changed")
                        main_dic[name][2]=new_phone
                        print(main_dic[name])
                        print
def write(main_dic):
      print()
      name = input ("Enter the name of a member:")
      print()
      print (mem_info.get(name,'Not found!'))
      print()
main()




























main()

Also any help or suggestions in making this code work are appreciated.

4

1 回答 1

3

这是格式问题。s 必须与它们所属的elifs 在同一列中开始。if

例子

if something:
    do_somtething()
elif something_else:
    do_the_other_thing()
于 2013-10-10T02:46:55.530 回答