145k views
4 votes
ComputeChange.py, to fix the possible loss of accuracy when converting a float value to an int value. Enter the input as an integer whose last two digits represent the cents. For example, the input 1156 represents 11 dollars and 56 cents.

1 Answer

1 vote

def compute_change(total_cents):

dollars = total_cents // 100

cents = total_cents % 100

return dollars, cents

def main():

total_cents = int(input("Enter an integer value for the total in cents: "))

dollars, cents = compute_change(total_cents)

print(f"{dollars} dollars and {cents} cents")

if __name__ == "__main__":

main()

User Robzero
by
7.5k points