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('

)

       

       #prici will have the price

       prici=(item[indexi+1:])

       

       #add the price of that item to total value

       total+=float(prici)

       

       #write the item and its price to the output file

       file2.write(item)

       

   #For any other inputs, it will print ("Wrong choice")

   else:

       print("Wrong choice")

       

   #It will ask the user, if he/she needs more orders

   print("Do you want to add more")

   order=(input("Enter order: "))

   

   #it will convert the user input into an integer, if possible

   #because he may enter "exit" also.

   try:

       order=int(order)

   except:

       continue

#This is the case outside of the while loop.

#Here, Total amount is printed in the bill.

file2.write("----------------------\n")

file2.write("Your Total amount is $"+str(total))

#We need to close those files as well

#close() function closes the file and frees the memory space acquired by that file.

file1.close()

file2.close()

See more about python at brainly.com/question/18502436

#SPJ1

Ver imagen lhmarianateixeira
Ver imagen lhmarianateixeira