Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculating with float
#1
This code fails:

import math
r=input("r=")
h=input("h=")
V=math.pi*h*r**2
print (V)
V=math.pi*h*r**2
TypeError: can't multiply sequence by non-int of type 'float'


While this works:

import math
r=3.5
h=9
V=math.pi*h*r**2
print (V)
Can someone tell me where the difference lies and how to make the first bit of code work?

Thanks
Reply


Messages In This Thread
Calculating with float - by TSheets13 - Oct-02-2019, 12:08 PM
RE: Calculating with float - by DeaD_EyE - Oct-02-2019, 12:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python calculate float plus float is incorrect? sirocawa 6 2,378 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key firebird 2 4,828 Jul-25-2019, 11:32 PM
Last Post: scidam

Forum Jump:

User Panel Messages

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