0

[SOLVED] Finding the amount of dollar, quarter, dime, nickel and pennys in a change given

Hey guys! Do any of you guys knows how to find the number of dollar, quarter, dime, nickel and pennys if let's say I've paid $110 for the items pricing $102.80., and given $7.20 back for the change. The output should be: Change: $7.20 Dollar: 7.00 Quarter: 0.20 Dime: 0.00 Pennys: 0.00. #What I did for the dollar is #and the only thing that was right. chge = 7.20 doll = int(chge/1.0) print("Dollar:", doll)

26th Sep 2017, 11:43 PM
Samantha philip
Samantha philip - avatar
1 Answer
+ 3
Hey @Samantha, I don't really understand the value of dime & penny, how many of those to make a dollar? I understand a quarter is one fourth a dollar, and a cent is one hundredth of a dollar, aren't dime & penny used with pound? sorry if it sounds silly, but I just don't know. Here's my idea (with what I know) about it: 1. Check if chg < 1, if so, it's less than 1 dollar, skip step 2 if this is the case. 2. Get the dollar by extracting the integer part, the quarter, etc are in the fraction part, e.g: change=7.20 dollar=7 (use int()), then subtract change by dollar to get remainder (0.20) no quarter found because remainder is less then 0.25 3. For the remainder of chg calculate how many dimes & pennies are there is by dividing remainder with their value. Hth, cmiiw
27th Sep 2017, 12:49 AM
Ipang