Well, I thought I'd ported the code from c pretty quickly and easily this time, but there is a problem I've been trying to work on for the best part of a week and I don't understand it....and I've tried everything I can find by searching...
I've asked for the 'change' as a float as suggested by the walkthrough (and it has to be anyway, I thought? because it needs to have to 2 dec places...) then I've tried to round it, to get it to no decimal places for the calculations. That didn't work so I changed the input to another var because a debugger I'm using said something about not being able to do calculations using the input function...nada! Then I tried to declare a var as an int and then change the input to that var so that it would be no dec places. That didn't work. So then I added a line to 'cast' the var (that's supposed to be an int to start with - I read that "= 0" makes it an int and '= x.0 makes it a float??!). Anyway, none of it works - I still end up with 2 dec points in the calculations. So then I 'cast' all the vars to ints just to make sure it wasn't coming from anywhere else...! Even that didn't work and I am at a loss...why isn't the 'money' var coming out with no dec points?? I don't feel I can move on and come back to it because without understanding why this is happening I feel I don't understand the basics of python... Any advice gratefully received...thank you!
import cs50
def main():
amt = 0
count = 0
counter = 0
money = 0
#prompt for change and confirm sum is more than 0
while True:
print("Input amount of change")
amt = cs50.get_float()
#convert input to a rounded number of cents ('money')
money = amt
int(money)
money = round(money * 100,0)
int(count)
int(counter)
#if there is money
while money >= 1:
#make sure money remains > 24 then count how many 25's in money
if money > 24:
counter = money / 25
money = money % 25
count = count + counter
counter = 0
# make sure money remains > 9 then count how many 10's in money
if money > 9:
counter = money / 10
money = money % 10
count = count + counter
counter = 0
# make sure money remains > 4 then count how many 5's in money
if money > 4:
counter = money / 5
money = money % 5
count = count + counter
counter = 0
# make sure money remains > 0 then count how many 1's in money
if money > 0:
counter = money / 1
money = money % 1
count = count + counter
counter = 0
if money == 0:
print(count)
break
if __name__ == "__main__":
main()