Respuesta :
Using the knowledge in computational language in python it is possible to write a code that uses enters menu items by name or an assigned item number.
Writting the code in python:
#Here, file1 is created as object for menu.txt and file2 as object for bill.txt
#It is done using the open() function.
#No module is required to be imported for this function.
#Here, r represents that this file will be used to read data
#and w represents "write"
file1 = open("menu.txt","r")
file2 = open("bill.txt","w")
#this is the welcome statement
print ("Welcome to the Delicious Restaurent:")
print("""Enter "I'm done" or "Exit" or "No" to stop the orders.\n""")
print("The menu is as follows:\nPlease enter the item no. to order.\n")
#readlines(): reads all the lines and return them as each line a string element in a list.
a=file1.readlines()
#we will iterate though each element and print it to the customer
for i in range(len(a)):
print("{}) {}".format(i+1,a[i]))
#variable to store the total bill amount
total=0
#initialize the order variable with 1
order=1
#taking the input
order=int(input("\nEnter order: "))
#This loop will continue untill the customer will enter "exit" or "I'm done"
while(order not in ["i'm done", "I'm done" ,"Exit", "exit","No","no"]):
#if customer enters "i'm done" or "exit", he will break out of loop
if order in ["i'm done", "I'm done" ,"Exit", "exit","no","No"]:
break
#if customer enters any number between 1 to 12, that item will be added to his bill
if order in range(1,13):
print("Your order number {} is added.\n".format(order))
#we will get that item by its order number
item=a[order-1]
#Here i am using string slicing to get the price(it is after the $ sign)
#We will get the index of $ sign and use the number after that
# for eg. "Egg burger $34.12"
# indexi= 11 (Here $ is at 11th position)
indexi=item.index('
Otras preguntas