mercredi 11 novembre 2015

Is this the correct way to implement dictionary?

       f=open('food.dat','w+')
       rates=0
       rate=0
       print"Menu is:"
       print"""   1.Starters
       2.Main Courses
       3.Snacks
       4.Drinks
       5.Desserts"""
       hotel_food1={1:'Starters',
       2:'Main Courses',
       3:'Snacks',
       4:'Drinks',
       5:'Desserts'}
       while True:
           food=input("Enter the food type:")
           if(hotel_food1.has_key(food)==1):
                     print"Menu is:"
                     print"""1.Salmon Devilled Eggs
                     2.Baked Parika Cheese
                     3.Ricotta and Parmesan Fritters
                     4.Traditional Welsh Cawl
                     5.Summer Ratatouille Salad"""
                     hotel_starter={1:'Salmon Devilled Eggs',
                      2:'Baked Parika Cheese',
                      3:'Ricotta and Parmesan Fritters',
                      4:'Traditional Welsh Cawl',
                      5:'Summer Ratatouille Salad'}
                     fd=input("ENter the food type")
                     if(hotel_starter.has_key(fd)==1):
                                               rate=rate+234
                     elif(hotel_starter.has_key(fd)==2):
                                          rate=rate+345
                     elif(hotel_starter.has_key(fd)==3):
                                       rate=rate+200
                     elif(hotel_starter.has_key(fd)==4):
                                       rate=rate+110
                     elif(hotel_starter.has_key(fd)==5):
                                        rate=rate+334
                     ch=raw_input("Do you want to continue? yes/no??")
                     if(ch=='no'):
                              break
       rates=rates+rate

       f.write(str(rates))


       f.seek(0,0)
       x=f.read()
       print x

       f.close()

Hello, In the above program when i give input for food as 1 and fd as 1 ,i must get the value 234 printed.but when i run the program i get value as 0. Is there something wrong with the indentation? Is the dictionary implemented correctly?? please help!Thank you!

Aucun commentaire:

Enregistrer un commentaire