TypeError: can't multiply sequence by non-int of type 'float' in Python
Dung Do Tien
Aug 15 2021
154
Hello you guys, I have a problem need your help. I created a small project with Python 3.8.2 to help calculate BMI points for humans. You can see like this:
weight = input('How much do you weigh?:')
height = input('How tall are you?:')
bmi = weight / (height * 2.0)
print('BMI: ', bmi)
But when I'm inputting weight = 80 and tall = 1.76 I get an error throw TypeError: can't multiply sequence by non-int of type 'float'
How much do you weigh?:80 How tall are you?:1.76 Traceback (most recent call last): File "main.py", line 3, in <module> bmi = weight / (height * 2.0) TypeError: can't multiply sequence by non-int of type 'float'
How can I resolve it?
Thanks for any suggestions.
Have 1 answer(s) found.
-
T0
Tran Quang Hung Aug 15 2021
You need to convert a string input value to float before calculate by using
float()
method, like:weight = float(input('How much do you weigh?:')) height = float(input('How tall are you?:')) bmi = weight / (height * 2.0) print('BMI: ', bmi)
How much do you weigh?:90 How tall are you?:1.80 BMI: 25.0
I hope it is useful for you.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.