31.8k views
1 vote
Please write in python:

Week 1 (Print menu and take a selection)

At program start, you will print a menu with the contents of your vending machine.

Customize your own vending machine with items of your interest

Your vending machine should have at least 5 items

Accept items to be purchased, or until a sentinel value is entered.

Print the selected item after each selection.

Week 2 (Take many selections, calculate total, and accept payment)

Extend your code to allow users to repeatedly select items for purchase and keep a running subtotal

Your menu should contain a sentinel value for the user to select checkout as an option to finish shopping.

Check that the selection entered is an option of the menu. If not, then print an error message and start over requesting a new selection or to quit.

Calculate amount due with subtotal + sales tax (for your state).

Accept payment in whole dollars

Following the deposit (payment), calculate change due (difference between payment and amount due)

Week 3 (Dispense change)

Extend your code to determine the dollars and coins to be dispensed from the change due or as a refund. This calculation will depend on the payment accepted. For example, if the user selected items totaling $10.35 and they only deposit $7.00, they have provided insufficient payment.

Check that the payment received is greater than or equal to the amount due. If the payment is less than the amount due, then print an error message and prompt the user to enter sufficient funds. If the payment is equal to the amount due, then print a message saying “No change due.”

Print the number of dollars and coins to be dispensed and their denominations.

Week 4 (Incorporating functions)

Extend your code to include the following functions,

print_menu(): non-value returning function to print out the menu at the start of the program and after each item for purchase is chosen. This menu should contain a sentinel for the user to checkout when the user is finished selecting items.

calculate_total(new_item): a value returning function to add up the cost of the item selected.

make_change(change_due): (previous lab assignment): Calculate the users change (“Here is your change: “) in dollars and coins and print a closing message (“Have a great day”).

amount_due(total_price): a value returning function that prints a subtotal and final total that includes sales tax (for your state) added to the total. This function will also require the user to input a whole dollar amount for payment and return the amount of change due and should prompt the user to retry if too little cash is paid.Write a program that reads a list of integers into a list as long as the integers are greater than zero, then output the smallest and largest integers in the list.

User Sasidhar
by
5.8k points

1 Answer

3 votes

Week 1:

print("1. Skittles 2. M&M's\\3. Starbursts 4. Twizzlers\\5. Twix")

while True:

item = input("Enter the number of your item to be purchased: ")

if item == "1":

print("You chose skittles.")

elif item == "2":

print("You chose M&M's.")

elif item == "3":

print("You chose Starbursts.")

elif item == "4":

print("You chose Twizzlers.")

elif item == "5":

print("You chose Twix.")

Week 2:

print("1. Skittles 2. M&M's\\3. Starbursts 4. Twizzlers\\5. Twix")

total = 0

while True:

item = input("Enter the number of your item to be purchased: ")

if item == "1":

print("You chose skittles.")

total += 2

elif item == "2":

print("You chose M&M's.")

total += 2

elif item == "3":

print("You chose Starbursts.")

total += 1

elif item == "4":

print("You chose Twizzlers.")

total += 3

elif item == "5":

print("You chose Twix.")

total += 4

elif item == "exit":

exit()

elif item == "out":

total += round(total*0.0625,2)

print("Your total is: ${}".format(total))

deposit = int(input("How much money did you input? "))

change_due = round(deposit - total,2)

print("Your change due is ${}".format(change_due))

else:

print("Please choose an option or enter \"exit\" to exit the vending machine.")

week 3:

print("1. Skittles 2. M&M's\\3. Starbursts 4. Twizzlers\\5. Twix")

total = 0

while True:

item = input("Enter the number of your item to be purchased: ")

if item == "1":

print("You chose skittles.")

total += 2

elif item == "2":

print("You chose M&M's.")

total += 2

elif item == "3":

print("You chose Starbursts.")

total += 1

elif item == "4":

print("You chose Twizzlers.")

total += 3

elif item == "5":

print("You chose Twix.")

total += 4

elif item == "exit":

exit()

elif item == "out":

total += round(total * 0.0625, 2)

print("Your total is: ${}".format(total))

deposit = int(input("How much money did you input? "))

while deposit < total:

deposit = int(

input("Please input a dollar amount greater than or equal to the total (whole numbers only): "))

change_due = round(deposit - total, 2)

if change_due == 0:

print("No change due.")

else:

print("You are owed {} dollars and {} cents".format(int(change_due), round(change_due - int(change_due),2)))

else:

print("Please choose an option or enter \"exit\" to exit the vending machine.")

week 4:

def print_menu():

print("1. Skittles 2. M&M's\\3. Starbursts 4. Twizzlers\\5. Twix Enter \"out\" to checkout.")

def calculate_total(new_item):

total = 0

if new_item == "1":

print("You chose skittles.")

total += 2

elif new_item == "2":

print("You chose M&M's.")

total += 2

elif new_item == "3":

print("You chose Starbursts.")

total += 1

elif new_item == "4":

print("You chose Twizzlers.")

total += 3

elif new_item == "5":

print("You chose Twix.")

total += 4

return total

def make_change(change_due):

print(

"Here is your change: {} dollars and {} cents".format(int(change_due), round(int(change_due) - change_due, 2)))

print("Have a great day")

def amount_due(total_price):

sales_tax = 0.0625

final_price = total_price * +(total_price * sales_tax)

print("Subtotal: {}".format(total_price))

print("Final total: {}".format(final_price))

deposit = int(input("Enter how much you deposited: "))

while deposit < final_price:

deposit = int(input("Enter an amount greater than or equal to {}".format(final_price)))

make_change(deposit - final_price)

total = 0

while True:

item = input("Enter the number of your item to be purchased: ")

if item == "1":

print("You chose skittles.")

total += 2

elif item == "2":

print("You chose M&M's.")

total += 2

elif item == "3":

print("You chose Starbursts.")

total += 1

elif item == "4":

print("You chose Twizzlers.")

total += 3

elif item == "5":

print("You chose Twix.")

total += 4

elif item == "exit":

exit()

elif item == "out":

sales_tax = 0.0625

total += round(total * sales_tax, 2)

print("Your total is: ${}".format(total))

deposit = int(input("How much money did you input? "))

while deposit < total:

deposit = int(

input("Please input a dollar amount greater than or equal to the total (whole numbers only): "))

change_due = round(deposit - total, 2)

if change_due == 0:

print("No change due.")

else:

print(

"You are owed {} dollars and {} cents".format(int(change_due), round(change_due - int(change_due), 2)))

else:

print("Please choose an option or enter \"exit\" to exit the vending machine.")

I didn't implement the functions because the problem never stated that we had to. Best of luck.

User Jason Byrd
by
5.7k points