Python Forum
Calculating with float - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Calculating with float (/thread-21501.html)



Calculating with float - TSheets13 - Oct-02-2019

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


RE: Calculating with float - DeaD_EyE - Oct-02-2019

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)