Write a program that simulates a vending machine. The machine holds six snack items labeled them...

60.1K

Verified Solution

Question

Programming

Write a program that simulates a vending machine. The machineholds six snack items labeled them 1 through 6. The program shouldinitially display a menu of items along with their prices:

Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00

The program then should ask the user to enter the item topurchase along with a sum of money. If the money is enough to buythe item, your program should display the name of item purchasedalong with the change owed to the user (if any). If the moneyinserted is insufficient, then your program should say so and letthe user know how much additional money is needed. Your programmust display the money amounts using the dollar sign and twodecimal places after the decimal point.

Please note that your program must validate theinput given by the user:

  • The item to purchase an the amount of money are numeric values(e.g. int and float)
  • If the user enters an invalid choice for an item to purchase,your program should alert the user of the error.
  • The program should not accept negative values for the sum ofmoney.

Here are a few sample runs:

Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: 1Enter money to purchase item: 10Thanks for buying Roasted Almonds.Your change is $8.75.
Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: 6Enter money to purchase item: 1.50You are $0.50 short.
Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: 9Invalid item choice.
Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: AValue entered was not a number.
Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: 2Enter money to purchase item: abcValue entered was not a number.
Vending Machine1. Roasted Almonds --> $1.252. Pretzels    --> $1.753. Chewing Gum   --> $0.904. Mints      --> $0.755. Chocolate bar  --> $1.506. Cookies     --> $2.00Enter your choice of item: 4Enter money to purchase item: -2.00Amount of money cannot be a negative value.

Notes:

  • The purpose of this problem is to practice usingconditional branching and the try/except clause.Do not use loops.
  • Please make sure to submit a well-written program. Goodidentifier names, useful comments, and spacing will be some of thecriteria that will be used when grading this assignment.
  • This assignment can be and must be solvedusing only the materials that have been discussed in class. Do notlook for alternative methods that have not been covered as part ofthis course.

How your program will be graded:

  • correctness: it performs the conversion correctly: 40%
  • complies with requirements: correct use of conditionalbranching: 40%
  • code style: good variable names, comments, proper indentationand spacing, : 20%

Please use python 3

Answer & Explanation Solved by verified expert
4.2 Ratings (710 Votes)
declaring    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students