Python Forum
I want to multiply two variables, but I get an error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I want to multiply two variables, but I get an error
#1
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
Reply
#2
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).
Reply
#3
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')
Reply
#4
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting error trying to use functions to multiply numbers rrowhe4d 5 1,879 Aug-30-2021, 07:11 AM
Last Post: Yoriz
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,077 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  error with variables 3.8 jusrosetyler1123 3 2,176 Dec-18-2019, 03:16 PM
Last Post: buran

Forum Jump:

User Panel Messages

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