Sep-15-2017, 05:53 AM
Guys and gals, I have lost my ever-loving mind. I was given a homework assignment (Intro to Python) and I have mostly figured this out, but I cannot get one thing right: When cents < 0, point back to require the input again (for now I have it break, but even that is broken). This is driving me crazy, there is something simple I am missing, I know it and I need a little nudge to get me to see it.
The assignment states I have to calculate a user defined value from 0-99 and kick back how many quarters, dimes, nickels and pennies are required to make that value (using highest value coins first, so if a single coin can hold a value/remainder, it must before a lower coin can fill any remaining void).
My issue is that even though I did just that, the teacher has kicked it back and states I need to have the input put back in when the value of cents < 0. I took a pseudo-code course last semester, but then was off all Summer, so I have forgotten a lot of the logic.
Python is hard, but I a pushing forward and am not asking anyone to do the work for me. I cannot figure out my logic here, I am missing something. I have made this far and dagburnit after two nights on this I have to move on and accept I don't see it. Please, someone, give me a hint, where have I failed logically to loop this back so I can learn from this horrible, horrible second program (our first program was Hello World!, and now this; yes, this is Week 2 homework). I bet it is easy... I just don't see it. My code is below, and real talk, thank all of you for what you do. I doubt many people aren't grateful, but trust me when I say that I am. Reading these forums has taught me so much and I hate I have to bother you for this little problem, but I must move on and learn from this; I can't hold up any longer, it is due in four days and I have given it my all. R.I.P. My Logic.
Cheers,
~Rod
The assignment states I have to calculate a user defined value from 0-99 and kick back how many quarters, dimes, nickels and pennies are required to make that value (using highest value coins first, so if a single coin can hold a value/remainder, it must before a lower coin can fill any remaining void).
My issue is that even though I did just that, the teacher has kicked it back and states I need to have the input put back in when the value of cents < 0. I took a pseudo-code course last semester, but then was off all Summer, so I have forgotten a lot of the logic.
Python is hard, but I a pushing forward and am not asking anyone to do the work for me. I cannot figure out my logic here, I am missing something. I have made this far and dagburnit after two nights on this I have to move on and accept I don't see it. Please, someone, give me a hint, where have I failed logically to loop this back so I can learn from this horrible, horrible second program (our first program was Hello World!, and now this; yes, this is Week 2 homework). I bet it is easy... I just don't see it. My code is below, and real talk, thank all of you for what you do. I doubt many people aren't grateful, but trust me when I say that I am. Reading these forums has taught me so much and I hate I have to bother you for this little problem, but I must move on and learn from this; I can't hold up any longer, it is due in four days and I have given it my all. R.I.P. My Logic.
Cheers,
~Rod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# program to get user-defined input (0-99) # program will calculate number of coins required to make exact change using highest value coins first # get user input # use int; float will not round decimals accurately for req'd math cents = int ( input ( "Enter change: Amount of change must be between 0 and 99.\n" )) # set each coin [quarter, dime, nickel, penny] to 0 quarter = 0 dime = 0 nickel = 0 penny = 0 # while loop to test if each addition will equal/overlap user-defined cents while cents > = 0 : if cents > = 25 : quarter + = 1 cents - = 25 elif cents > = 10 : dime + = 1 cents - = 10 elif cents > = 5 : nickel + = 1 cents - = 5 elif cents > = 1 : penny + = 1 cents - = 1 else : print ( "Amount of change must be between 0 and 99.\n" ) break # set list # guessing here: >>> list0 = [quarter, dime, nickel, penny] # output message displaying appropriate coins to equal user-defined cents print ( "Quarters:" , quarter) print ( "Dimes:" , dime) print ( "Nickels:" , nickel) print ( "Pennies:" , penny) |