Question

In: Computer Science

IN BASIC PYTHON: Cafeteria Selections Program. This program permits students to choose their lunch purchases from...

IN BASIC PYTHON:

Cafeteria Selections Program. This program permits students to choose their lunch purchases from a menu in the cafeteria. It calculates the tax on taxable items (candy, pop) and presents the user with a total. The program accepts a tendered amount and computes and outputs change down to the actual coins and bills involved. An added inventory component could keep a running total of individual items purchased. No graphics needed here.

Mars Bar $1.25

Kit Kat $1.25

Soda Pop $1.50

Water $1.00

Muffins $2,00

Coffee / Tea $1.75

Expresso / Specialty Teas $2.50

Cold Sandwiches $5.00

Pasta $7.50

Gum $.140

Solutions

Expert Solution

PYTHON CODE:

# viewMenu() prints all the items 
def viewMenu(itemPrice):
    for key, value in itemPrice.items():
        print(key + ": $" + str(value));
    print("");
# addItemsToCart() checks if its a valid item and calculates tax
# creates a dictionary which has the items and total value (value * quantity)
def addItemToCart(itemPrice, itemCart):
    cont = "Y";
    while(cont == "Y"):
        # Gets user input for which item to add to the cart
        item = input("Enter the item to add: ");
        try:
            #checks if its a valid entry(if the item is present in the itemPrice dictionary)
            itemValue = itemPrice[item]; 
            # If valid, next line will be executed. 
            if(item == "Mars Bar" or item == "Kit Kat" or item == "Soda Pop"):
                tax = 0.13 * itemValue; # calculates tax for Mars Bar, Kit Kat and Soda Pop
                itemValue = itemValue + tax; # calculates itemValue with tax
            # Gets user input for the quantity
            quantity = int(input("Enter the quantity to add: "));
            try:
                # If the item is already present in the cart, value will be added to
                # the exisiting amount
                if(itemCart[item] > 0):
                    itemCart[item] += itemValue * quantity;
            except KeyError:
                itemCart[item] = itemValue * quantity;
            # Asks user if they would like to add more items
            cont = input("Do you want to continue? (y or n)").upper();            
        # if the item is not present in the itemPrice dictionary, this will be executed
        except KeyError:
            print("Invalid item");
            cont == "Y";
    return itemCart;

# viewItemsInCart() prints all the items in the cart
def viewItemsInCart(itemCart):
    total = 0;
    # If no item is present
    if(not bool(itemCart)):
        print("Cart is empty");
        print("");
    # If the cart is not empty, it prints the values in the cart
    else:
        print("Items in the cart");
        for key, value in itemCart.items():
            print(key + ": $" + str(value));
            total += value;
        print(""); 
    return total;
            
# payBill() displays the total amount and returns the extra amount
def payBill(itemCart):
    totalAmount = viewItemsInCart(itemCart);
    print("Total amount: " + str(totalAmount));
    tenderedAmount = int(input("Pay the amount here: "));
    # Checks if the amount paid by the user is lesser than the amount to be paid
    if(tenderedAmount < totalAmount):
        print("");
        print("Invalid value");
        print("");
        payBill(itemCart);
    # Calculates the amount to be returned
    else:
        cashback = tenderedAmount - totalAmount;
        print("Amount Paid: $" + str(tenderedAmount));
        print("Change Back Amount: $" + str(cashback));

# Dictionary with items and values   
itemPrice = {"Mars Bar": 1.25, "Kit Kat": 1.25, "Soda Pop": 1.50, "Water": 1.00,
             "Muffins": 2.00, "Coffee/Tea": 1.75, "Expresso/Speciality Teas": 2.50,
             "Cold Sandwiches": 5.00, "Pasta": 7.50, "Gum": 0.140};
itemCart = {};
mainMenuInput = "1";
while(mainMenuInput != "4"):
    # Displays Menu where user can select what they would like to do
    print("Welcome to the Cafeteria");
    print("Please select any of the following options");
    print("1. View the menu");
    print("2. Add items to the cart");
    print("3. View items in the cart");
    print("4. Pay the bill and buy");
    print("Enter any other value to quit the program");
    mainMenuInput = input();
    if(mainMenuInput == "1"):
        viewMenu(itemPrice);
    elif (mainMenuInput == "2"):
        itemCart = addItemToCart(itemPrice, itemCart);
    elif (mainMenuInput == "3"):
        viewItemsInCart(itemCart);
    elif (mainMenuInput == "4"):
        payBill(itemCart);
    else:
        break;

OUTPUT:


Related Solutions

In PYTHON : as basic as possible Write a program that acts as a cash register....
In PYTHON : as basic as possible Write a program that acts as a cash register. The program will prompt how many items they are buying. Then they will input the price of each item (these should be decimal numbers). The program will display the SUBTOTAL, TAX ADDED (13%), and the TOTAL (with tax). Make sure you include $ signs and round to two decimal places ] Sample Output: How many items are you buying? 3 Enter in a price:...
Choose two applications from the list below. You should make your selections so that you are...
Choose two applications from the list below. You should make your selections so that you are able to describe both points of similarity and points of difference when answering the questions that follow. • Electronic file transfer • Electronic mail • Bit-torrent • Internet Relay Chat (IRC) • The Domain Name System (DNS) • IP Telephony (VoIP, not Skype or Facetime, etc.) • Real-time streaming (Not web-based solutions such as Youtube, Facebook, Instagram, etc.) Answer the following questions about both...
1/ Instructions: Choose one answer from each pair of selections. Overcast skies usually result in cooler...
1/ Instructions: Choose one answer from each pair of selections. Overcast skies usually result in cooler daytime temperatures because clouds are good REFLECTORS | ABSORBERS of sunlight. 2/ Instructions: Choose one answer from each pair of selections. Compared to Phoenix (30°N latitude), Minneapolis (45°N) will have shorter days in the winter and LONGER | SHORTER days in the summer. 3/ Match each item with the appropriate description. conduction[ Choose ]​the transfer of heat by the mass movement of a fluid,...
Python: Write a program to simulate the purchases in a grocery store. A customer may buy...
Python: Write a program to simulate the purchases in a grocery store. A customer may buy any number of items. So, you should use a while loop. Your program should read an item first and then read the price until you enter a terminal value (‘done’) to end the loop. You should add all the prices inside the loop. Add then a sales tax of 8.75% to the total price. Print a receipt to indicate all the details of the...
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program...
1. INTRODUCTION The goal of this programming assignment is for students to write a Python program that uses repetition (i.e. “loops”) and decision structures to solve a problem. 2. PROBLEM DEFINITION  Write a Python program that performs simple math operations. It will present the user with a menu and prompt the user for an option to be selected, such as: (1) addition (2) subtraction (3) multiplication (4) division (5) quit Please select an option (1 – 5) from the...
Project Outcomes: Develop a python program that uses:  decision constructs  looping constructs  basic...
Project Outcomes: Develop a python program that uses:  decision constructs  looping constructs  basic operations on an list of objects (find, change, access all elements)  more than one class and has multiple objects Project Requirements: 1. Develop a simple Hotel program. We will have two classes, a Hotel class representing an individual hotel and a Room class. The Hotel class will contain several Room objects and will have several operations. We will also have a driver program...
write a small visual basic console program to output the ages of three students
write a small visual basic console program to output the ages of three students
IN PYTHON create a python program that accepts input from the user in the following sequence:...
IN PYTHON create a python program that accepts input from the user in the following sequence: 1. Planet Name 2. Planet Gravitational Force(g) for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are: 1. planetName 2. planet GravitationalForce(g) A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of...
Create a new Python program (you choose the filename) that contains a main function and another...
Create a new Python program (you choose the filename) that contains a main function and another function named change_list. Refer to the SAMPLE OUTPUT after reading the following requirements. In the main function: create an empty list. use a for loop to add 12 random integers, all ranging from 50 to 100, to the list. use second for loop to iterate over the list and display all elements on one line separated by a single space. display the 4th element,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT