Project #14297 - Python - nested loop

In this question you will practice implementing selection statements and nested loops.

                          

The purpose of this assignment is to develop a program that repeatedly asks the user to input coin values until the total amount matches a target value. Thetarget value is a randomly generated integer between 1 and 99 inclusively.

                                            

                                             

For example, for a target value of 31, coin values entered by the user should be 25, 5and because 31 = 25 + 5 + 1.

                                        

                         

You should start writing your program code first by downloading the template provided. It is shown in the template how to generate a random integer by calling the function randint(a,b) from the module sgenrand.py, so in order to run your program you should also download this module and put it in the same directory as your program.

                       

                            

                     

Input/Output

                     

Below is a sample run of the program. The output of your program should exactly match the sample.

 


The purpose of this exercise is to enter a number of coin values
that add up to a displayed target value.

Enter coins values as 1-penny, 5-nickel, 10-dime,and 25-quarter.
Hit return after the last entered coin value.
--------------------
Enter coins that add up to 81 cents, one per line.

Enter first coin: 25
Enter next coin: 25
Enter next coin: 
Sorry - you only entered 50 cents.

Try again (y/n)?: y
Enter coins that add up to 99 cents, one per line.

Enter first coin: 25
Enter next coin: 25
Enter next coin: 25
Enter next coin: 24
Invalid entry
Enter next coin: 25
Sorry - total amount exceeds 99 cents.

Try again (y/n)?: y
Enter coins that add up to 51 cents, one per line.

Enter first coin: 50
Invalid entry
Enter first coin: 25
Enter next coin: 25
Enter next coin: 1
Enter next coin: 
Correct!

Try again (y/n)?: n
Thanks for playing ... goodbye

Subject Computer
Due By (Pacific Time) 10/11/2013 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy