bilal = input("Please enter a number")
if bilal == 1:
print(multiplcation())
elif bilal==2:
print(divison())
else:
print(rasied_to_the_power())
def multiplcation(a=int(input("enter a number :")),b= int(input("enter a number :"))):
return a*b
print(multiplcation())
def divison(a=int(input("enter a number :")),b= int(input("enter a number :"))):
return a/b
print(divison())
def rasied_to_the_power(a=int(input("enter a number :")),b= int(input("enter a number :"))):
return a**b
print(rasied_to_the_power())
上面你可以看到我的代码。当我输入1时输出运行,从我认为它应该运行乘法函数,如果我输入2,它应该运行除数函数。但是我不断地犯错误。我有什么不明白的地方吗。我得到的错误是
Please enter a number 1
Traceback (most recent call last):
File "<string>", line 6, in <module>
NameError: name 'divison' is not defined
以下是输出的两个链接:
将
bilal = input("Please enter a number")
更改为bilal = int(input("Please enter a number"))
,因为您正在将值检查为整数,并在代码上方编写函数,因为python自上而下读取它请用正确的方式写函数
与其那样写,不如这样写
这三个函数都是一样的
以下是全部编辑的代码,请改用它:
Python是自上而下计算的。您需要在使用函数之前定义它们
对于第二个错误,您定义了期望输入
(a, b)
的函数。您已经在没有输入的情况下调用了每个函数相关问题 更多 >
编程相关推荐