这段代码有错误吗?如果是让我知道?
Is there any mistake in this Code ? if it is let me know?
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 )
I can't find the exact output I'm a beginner So guide me please,
您需要使函数 return 的值:
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 )
您必须return这些值才能在函数外使用它们
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 )
您不能在函数外访问函数变量。 PLace 函数内的打印语句或函数中的 return 值,如下所述。
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 )
I can't find the exact output I'm a beginner So guide me please,
您需要使函数 return 的值:
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 )
您必须return这些值才能在函数外使用它们
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 )
您不能在函数外访问函数变量。 PLace 函数内的打印语句或函数中的 return 值,如下所述。