0

This is my code and whenever I call my function truncate in python the program stops when I am trying to make it round. Any help is appreciated thanks!

''' from cs50 import get_float
cash = get_float("How much change do we owe: ")
while cash < 0:
cash = get_float("How much change do we owe: ")
print(f"Change owed: {cash}")

def truncate(n):
multiplier = 100
return round(n * multiplier) / multiplier

cash_counter = 0
while cash > 0.00:
     if truncate(cash) > 0.25:
         cash_counter = cash_counter + 1
         cash = cash - 0.25

    elif truncate(cash) > 0.10:
         cash_counter = cash_counter + 1
         cash = cash - 0.10

    elif truncate(cash) > 0.05:
         cash_counter = cash_counter + 1
         cash = cash - 0.05

    elif truncate(cash) > 0.01:
         cash_counter = cash_counter + 1
         cash = cash - 0.01

print(cash_counter)'''

1 Answer 1

1

What's your equation.... let's say cash is = 4.2. so 4.2 * 100 = 420, round(420) = 420, 420 / 100 = 4.2? You just did a lot of work just to get back to step 1.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .