f=open('foo.dat','w+')
rate=0
print"Menu is:"
print"""1. Indian
2.Italian
3.Chinese
4.COntinential
5.Starters and drinks"""
hotel_food={1:'Indian',2:'Italian',3:'Chinese'}
f.write(str(hotel_food))
food=input("Enter the food type:")
f.write(str(food))
if(hotel_food.has_key(food)):
print"Menu is:"
print"""1. Roti with Curry
2.South Indian Cuisines
3.festival dishes
4.sea food"""
hotel_food1={1:'Roti with Curry',
2:'South Indian Cuisines'}
f.write(str(hotel_food1))
fd=input("ENter the food type")
f.write(str(fd))
if(hotel_food1.has_key(fd)):
rate=rate+1234
print rate
l=f.write(str(rate))
x=f.read(l)
print x
f.close()
This program allows user to input the type of food they want and the subtype as well. after that the bill or rate is calculated.
When I run the program, the error is: x=f.read(l)
TypeError: an integer is required
but when I make it into : x=f.read(str(l))
the same error comes: x=f.read(str(l))
TypeError: an integer is required.
Here, only one case is shown even though the menu has 5 cases, that is selecting Indian food and roti with curry. If this gets correct, I will do the rest.
Is this the right way to implement files in python? I can't write anything into file.