python - 本守则有任何错误吗?如果是让我知道?
问题描述
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 )
推荐阅读
- c++ - 在 emplace() 中创建对象时复制省略
- java - 使用 Java 8 按字符串属性对列表进行排序
- c# - 将 json 转换为对象时出现错误
- list - prolog 匹配项从列表到谓词
- c# - 在回发的会话中保持 ListBox 选择
- r - 使用带有变量标签的 rvest 进行抓取
- javascript - 加载页面时Javascript旋转圆圈动画不会停止
- spring - Spring @Value 使用通配符
- firebase - 如何使用 Firebase Node.js SDK 创建长期存在的令牌
- r - Plot predicted values from lmer longitudinal analysis