Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Coin Exchange using python. Modify the Coin Change Exercise program in section 3.4.6 so that the least possible number of coins must be entered. For
Coin Exchange using python.
Modify the Coin Change Exercise program in section 3.4.6 so that the least possible number of coins must be entered. For example, the least number of coins that total to 43 cents is 6 (one quarter, one dime, one nickel, and three pennies).
Please do not use anything past Chapter 3. This is a beginner computer science course. Please insert as little code as possible without a ton of if, elif statements I have seen some others use. Please stick to this code. Modify only.
# Coin Change Exercise Program import random # program greeting print('The purpose of this exercise is to enter a number of coin values') print('that add up to a displayed target value. print('Enter coins values as 1-penny, 5-nickel, 10-dime and 25-quarter') print("Hit return after the last entered coin value.") print(' # init terminate = False empty str -'' # start game while not terminate: amount random. ranaint (1, 99) print('Enter coins that add up to', amount, "cents, one per line. ') gameover-False total = 01 while not game over: valid entry-False while not valid entrv: if total -- 0: entry -input ('Enter first coin:') else: entry = input ('Enter next coin: if entry in (empty str, ' 1 ' , ' 5 ' , ' 10 ' , ' 25' ) : valid entry -True else: print (Invalid entry') If entry == empty str: if total amount: print('Correct!') else: print('Sorry - you only entered', total, 'cents.') game over = True else: total = total + int (entry) if total > amount: print ('Sorry - total amount exceeds', amount, 'cents.') if game_over: entry= input (' Try again (y)?: ') if entry' terminate-True print ('Thanks for playing goodbye')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started