Typeerror("unsupported Operand Type(s) For ** Or Pow(): 'str' And 'int'",)
import math A = input('Enter Wright in KG PLease :') B = input('Enter Height in Meters Please :') while (any(x.isalpha() for x in A)): print('No Letters Please') A = in
Solution 1:
Try doing
B = float(input( "Enter Height in meters : "))
Solution 2:
You can make this less complicated by casting to float and catching ValueError
to detect invalid input. Note that it'd be more user-friendly to split this into two while
loops, one each for a
and b
, but this is just to illustrate the idea:
a = b = Nonewhilenot (a and b):
try:
a = float(input("Weight (kg): "))
b = float(input("Height (m): "))
except ValueError:
print("Invalid input")
c = a / (b ** 2)
if c <= 18.5:
print("Underweight")
elif18.5 < c < 25:
print("Healthy weight")
else:
print("Overweight")
Also, not (a and b)
will keep requesting input in the event that one of the inputs was zero, which I think is appropriate behavior in this case.
Post a Comment for "Typeerror("unsupported Operand Type(s) For ** Or Pow(): 'str' And 'int'",)"