Python 这个代码有错误吗?如果有,请告诉我?
我找不到确切的输出,我是初学者,请引导我Python 这个代码有错误吗?如果有,请告诉我?,python,calculator,Python,Calculator,我找不到确切的输出,我是初学者,请引导我 您需要使函数返回以下值: a = int(input("Enter Your First Number=")) b = int(input("\nEnter Your Second Number=")) def cal(): sum = a + b sub = a - b mul = a * b div = a % b cal() print("\nAddtio
您需要使函数返回以下值:
a = int(input("Enter Your First Number="))
b = int(input("\nEnter Your Second Number="))
def cal():
sum = a + b
sub = a - b
mul = a * b
div = a % b
cal()
print("\nAddtion of Two Number is =" , sum)
print("\nSubtraction of Two Number is =" , sub )
print("\nMultiplication of Two Number is =" , mul )
print("\nDivision of Two Number is =" , div )
必须返回值才能在函数外部使用它们
a = int(input("Enter Your First Number="))
b = int(input("\nEnter Your Second Number="))
def cal():
sum = a + b
sub = a - b
mul = a * b
div = a % b
return sum, sub, mul, div
sum, sub, mul, div = cal()
print("\nAddtion of Two Number is =" , sum)
print("\nSubtraction of Two Number is =" , sub )
print("\nMultiplication of Two Number is =" , mul )
print("\nDivision of Two Number is =" , div )
您不能访问函数之外的函数变量。将打印语句放置在函数中,如下面提到的函数中的返回值。< /P >错误1:此代码是Python,但您添加java和C++标签,没有理由错误2:您正在尝试访问函数之外的函数局部变量,在那里不再有SCANEDWONBORD被遗忘…可能需要编辑该标题,并提供有关实际存在的问题/错误的更多详细信息
cal=lambda:(a+b,a-b,a*b,a%b)
然后sum,sub,mul,div=cal()。
a = int(input("Enter Your First Number="))
b = int(input("\nEnter Your Second Number="))
def cal():
return a + b, a - b, a * b, a % b
add,sub,mul,div = cal()
print("\nAddtion of Two Number is =" , add)
print("\nSubtraction of Two Number is =" , sub )
print("\nMultiplication of Two Number is =" , mul )
print("\nDivision of Two Number is =" , div )