Python Forum
why is there an unexpected maths result from a float calculation?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is there an unexpected maths result from a float calculation?
#1
One of my students asked why - entering 35 as the input gets a strange answer - see print dollars result. It is strange. The answer should just be 0.35

pennies = int(input('Enter pennies: '))
dollars = pennies * .01
print(f'{pennies} pennies are worth ${dollars:.2f} in dollars')
print(dollars)
Reply


Messages In This Thread
why is there an unexpected maths result from a float calculation? - by maryab - Jun-08-2019, 10:00 AM
RE: unexpected math resule - by Yoriz - Jun-08-2019, 10:15 AM
RE: unexpected math resule - by Gribouillis - Jun-08-2019, 10:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Maths and python: Compute stress level cheerful 1 2,787 Oct-20-2021, 10:05 AM
Last Post: Larz60+
  Increasing difficulty of a maths game Maxxy_Gray 1 3,257 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot
  Making maths .py program faster Shutcois 1 2,693 Feb-16-2018, 06:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020