Python Forum

Full Version: I want to multiply two variables, but I get an error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have two questions.

First: I want to multiply two variables, but I get an error. How can I solve it?
here is my Code:

Name = 'Random'
Height = 1,65
Weight = 52
bmi = Weight / (Height * Height)
print ('Name: ')
print (Name)
print ('BMI: ')
print (bmi)
print (Name)
if bmi < 25:
    print ('is underweight')
elif bmi > 25:
    print ('is overweight')
elif bmi == 25:
    print ('is normal-weight')
Error:
Traceback (most recent call last): File "D:/Python Scripts/if-Abfrage Testen.py", line 4, in <module> bmi = Weight / (Height * Height) TypeError: can't multiply sequence by non-int of type 'tuple'
My second question: How can I make, that it prints the name of the person and the type of weigh it has in one line?
Like that: "Random is overweight"

Hope, you can help me. Here is a smiley for you Smile
Do not use comma to mark the decimal place. Use period. By using a comma you told python that height is a tuple, two numbers (1, 65).
Thanks for the smiley

Using f strings for the print statements
name = 'Random'
height = 1.65
weight = 52
bmi = weight / (height * height)
print(f'Name: {name}\nBMI: {bmi}')
if bmi < 25:
    print(f'{name} is underweight')
elif bmi > 25:
    print(f'{name} is overweight')
elif bmi == 25:
    print(f'{name} is normal-weight')
(Aug-09-2020, 03:43 PM)deanhystad Wrote: [ -> ]Do not use comma to mark the decimal place. Use period. By using a comma you told python that height is a tuple, two numbers (1, 65).

Thanks, that worked Smile

(Aug-09-2020, 03:52 PM)Yoriz Wrote: [ -> ]Thanks for the smiley

Using f strings for the print statements
name = 'Random'
height = 1.65
weight = 52
bmi = weight / (height * height)
print(f'Name: {name}\nBMI: {bmi}')
if bmi < 25:
    print(f'{name} is underweight')
elif bmi > 25:
    print(f'{name} is overweight')
elif bmi == 25:
    print(f'{name} is normal-weight')
Also thanks to you Smile