TypeError: must be real number, not str
47,003
Use int
not str
from math import*
num1 = input("Enter the num ")
num2 = input("Enter the power ")
def exponent_func( num1 , num2):
return(pow ( int(num1) , int(num2) ))
exponent_func(num1 , num2)
Related videos on Youtube
Author by
Amy
Updated on July 31, 2022Comments
-
Amy over 1 year
Whenever I rum the code, error message "TypeError: must be real number, not str" displays
from math import* num1 = input("Enter the num ") num2 = input("Enter the power ") def exponent_func( num1 , num2): return(pow ( str(num1) , str(num2) )) exponent_func(num1 , num2)
-
pault over 5 yearsYou're casting the inputs to
pow
asstr
-
-
pault over 5 yearsand what if someone wanted to get the square root of
num1
? -
Amy over 5 yearsThen we would use sqrt(x)
-
pault over 5 years@Amy what if someone wanted to get
num1
raised to the power0.1
? I'm not being pedantic here, but it's important to understand why what you did does not work and what the limitations of this answer are. Edit: It's also worth reading Why isimport *
bad? -
Amy over 5 yearsWell this is my first day into Python programming and I don't have much experience in programming so this was just to get familiar with the syntax. I have updated my code to use
float
instead ofint
Thanks for the link!