类型错误:必须是实数,而不是 str

Amy*_*my 2 python

每当我朗读代码时,都会显示错误消息“TypeError: must be real number, not str”

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)
Run Code Online (Sandbox Code Playgroud)

max*_*axm 5

int不使用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)
Run Code Online (Sandbox Code Playgroud)

  • 如果有人想得到 `num1` 的平方根怎么办? (2认同)