Reputation: 9
weight = print(int(input('weight: ')))
height = print (float(input('height: ')))
BMI = weight * height
print(BMI)
#i get this back
Traceback (most recent call last):
File "C:/Users/Nicholas/Desktop/csp 17/Assign 3-2.py", line 4, in <module>
BMI = weight * height
TypeError: unsupported operand type(s) for *: 'NoneType' and 'NoneType'
Upvotes: 0
Views: 39
Reputation: 51395
print
does just that: it prints things to your screen. Because it is a function that doesn't return anything else, it will implicitely return None
.
You can verify this with a list comprehension if you want:
>>> x = [print(i) for i in range(5)]
0
1
2
3
4
>>> x
[None, None, None, None, None]
Notice that everything is printed, but the resulting variable is a list full of None
s.
For your code, try without the print
, because what you're trying to do is not print those things, but assign the variables weight
and height
to the inputed value:
weight = int(input('weight: '))
height = float(input('height: '))
BMI = weight * height
print(BMI)
Upvotes: 3