1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lianna [129]
2 years ago
14

User enters menu items by name or an assigned item number.

Computers and Technology
1 answer:
Lesechka [4]2 years ago
5 0

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.

<h3>Writting the code in python:</h3>

<em>#Here, file1 is created as object for menu.txt and file2 as object for bill.txt</em>

<em>#It is done using the open() function.</em>

<em>#No module is required to be imported for this function.</em>

<em>#Here, r represents that this file will be used to read data</em>

<em>#and w represents "write"</em>

<em>file1 = open("menu.txt","r")</em>

<em>file2 = open("bill.txt","w")</em>

<em />

<em>#this is the welcome statement</em>

<em>print ("Welcome to the Delicious Restaurent:")</em>

<em>print("""Enter "I'm done" or "Exit" or "No" to stop the orders.\n""")</em>

<em>print("The menu is as follows:\nPlease enter the item no. to order.\n")</em>

<em />

<em>#readlines(): reads all the lines and return them as each line a string element in a list.</em>

<em>a=file1.readlines()</em>

<em />

<em>#we will iterate though each element and print it to the customer</em>

<em>for i in range(len(a)):</em>

<em>    print("{}) {}".format(i+1,a[i]))</em>

<em>    </em>

<em>#variable to store the total bill amount</em>

<em>total=0</em>

<em />

<em>#initialize the order variable with 1</em>

<em>order=1</em>

<em />

<em>#taking the input</em>

<em>order=int(input("\nEnter order: "))</em>

<em />

<em>#This loop will continue untill the customer will enter "exit" or "I'm done"</em>

<em>while(order not in ["i'm done", "I'm done" ,"Exit", "exit","No","no"]):</em>

<em>    </em>

<em>    #if customer enters "i'm done" or "exit", he will break out of loop</em>

<em>    if order in ["i'm done", "I'm done" ,"Exit", "exit","no","No"]:</em>

<em>        break</em>

<em>    </em>

<em>    #if customer enters any number between 1 to 12, that item will be added to his bill</em>

<em>    if order in range(1,13):</em>

<em>        </em>

<em>        print("Your order number {} is added.\n".format(order))</em>

<em>        </em>

<em>        #we will get that item by its order number</em>

<em>        item=a[order-1]</em>

<em>        </em>

<em>        #Here i am using string slicing to get the price(it is after the $ sign)</em>

<em>        #We will get the index of $ sign and use the number after that</em>

<em>        # for eg. "Egg burger $34.12"</em>

<em>        # indexi= 11 (Here $ is at 11th position)</em>

<em>        indexi=item.index('$')</em>

<em>        </em>

<em>        #prici will have the price</em>

<em>        prici=(item[indexi+1:])</em>

<em>        </em>

<em>        #add the price of that item to total value</em>

<em>        total+=float(prici)</em>

<em>        </em>

<em>        #write the item and its price to the output file </em>

<em>        file2.write(item)</em>

<em>        </em>

<em>    #For any other inputs, it will print ("Wrong choice")</em>

<em>    else:</em>

<em>        print("Wrong choice")</em>

<em>        </em>

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

<em>    print("Do you want to add more")</em>

<em>    order=(input("Enter order: "))</em>

<em>    </em>

<em>    #it will convert the user input into an integer, if possible</em>

<em>    #because he may enter "exit" also. </em>

<em>    try:</em>

<em>        order=int(order)</em>

<em>    except:</em>

<em>        continue</em>

<em />

<em />

<em>#This is the case outside of the while loop.</em>

<em>#Here, Total amount is printed in the bill.</em>

<em>file2.write("----------------------\n")</em>

<em>file2.write("Your Total amount is $"+str(total))</em>

<em />

<em>#We need to close those files as well</em>

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

<em>file1.close()</em>

<em>file2.close()</em>

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

#SPJ1

You might be interested in
Why might it be a good idea to choose a bus topology?
Shtirlitz [24]

Answer:A

Explanation: Its cheap and easy to install

7 0
3 years ago
Read 2 more answers
This is Very very Important to me[BRAINLIEST)✅​
sineoko [7]

Answer:

Rom

mellisa

Explanation:

pls mark me BRAINLIAST

4 0
3 years ago
When a single controller device communicates with multiple peripheral devices, what wires are simultaneously connected to all de
Tems11 [23]

The wires that are simultaneously connected to all devices in the network are;

SDA(Serial data line) and SCL

Integrated Circuits Communication

This involves I²C which is a form of communication based on integrated circuits.

Now, this I²C is a serial communication interface that has a bidirectional two-wire synchronous serial bus which usually comprises of two wires namely SDA (Serial data line) and SCL (Serial clock line).

Read more about integrated circuits communication at; brainly.com/question/26153031

7 0
3 years ago
The "edit" command must allow the user to find a record in the list by director. If there are multiple records with the same dir
sveticcg [70]

Answer:

To allow user to assign rating

Explanation:

The basic function of “rate” command is to give opportunity to the user to assign a value to a song from the range of 1 – 5.

In the range, the value of 1 indicates the lowest rating, while value of 5 is the highest rating that can be obtained.

Any previous ratings are then replaced by the new rating assigned from the range of 1 – 5.

7 0
3 years ago
Create the content for your website.
arlik [135]
What do you need help with? I’m confused
5 0
3 years ago
Other questions:
  • Claim: Raising the minimum wage does not help most minimum wage employees Reason: Many small businesses cannot afford high minim
    14·2 answers
  • The "network of networks," consisting of LANs (Local Area Networksnetworks connecting two or more computers, usually within the
    5·1 answer
  • Which attribute of the image tag specifies the URL of an image
    14·1 answer
  • The CSS property of top , bottom , left , or right moves the element the specified distance from the respective edge of the clos
    7·1 answer
  • Jim wants to buy a car, but he’ll probably only need it for a couple of years. He has a short commute to work, so he won’t be pu
    5·1 answer
  • What is the difference between = and == in terms of java..?
    6·2 answers
  • Write a program that keeps track of a simple inventory for a store. While there are still items left in the inventory, ask the u
    12·2 answers
  • Cual es la fiabilidad de la innovacion tecnologica
    15·1 answer
  • Please solve this in JAVA<br><br> Please see the attachment
    10·1 answer
  • which one of the following would not normally be found in an organization's information security policy?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!