+ 1

Error: must be real number, not str

Hi, why in the following block I get this error: "must be real number, not str" import math def sqrt_root(x): return math.sqrt(x) x = input("Enter your number:") print("The SQR ROOT of ", x, " is:", sqrt_root(x))

12th Apr 2018, 11:06 AM
Soheil Rad
2 odpowiedzi
+ 4
When you call the function, call it like this: sqrt_root(int(x)) You are passing in a string, gotten from input, into a function that requires a integer. You need to convert it using the int() function.
12th Apr 2018, 11:11 AM
Ariela
Ariela - avatar
- 1
Ariela your suggestion worked. Thanks for your clear answer
12th Apr 2018, 11:19 AM
Soheil Rad