Python Forum

Full Version: Calculating with float
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
The built-in function returns a input.
Python is not JavaScript. Python is has a strong typing system.

Just convert the str to int or float:

f = float(input('Enter a float: '))
i = int(intput('Enter an int: '))

print(f+i)