首页 > 解决方案 > 本守则有任何错误吗?如果是让我知道?

问题描述

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  )

我找不到确切的输出我是初学者所以请指导我,

标签: pythoncalculator

解决方案


您需要使函数返回值:

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  )

推荐阅读