5

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)
Amy
  • 109
  • 1
  • 1
  • 5

2 Answers2

9

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)
maxm
  • 3,412
  • 1
  • 19
  • 27
  • 2
    and what if someone wanted to get the square root of `num1`? – pault Oct 22 '18 at 16:55
  • Then we would use sqrt(x) – Amy Oct 22 '18 at 17:03
  • 1
    @Amy what if someone wanted to get `num1` raised to the power `0.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 is `import *` bad](https://stackoverflow.com/questions/2386714/why-is-import-bad)? – pault Oct 22 '18 at 17:44
  • Well 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 of `int ` Thanks for the link! – Amy Oct 23 '18 at 15:55
0

You want to make the string inputs into floats or ints.num1 = float(num1)