首页 > 编程知识 正文

Python 程序:两个数相减

时间:2023-11-24 15:33:37 阅读:308778 作者:YWWH

写一个 Python 程序来减去两个数字。

num1 = 128
num2 = 256

sub = num1 - num2
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))
The Result of subtracting 256 from 128 = -128

这个 Python 程序接受两个整数值,并从另一个数中减去一个数。

num1 = int(input("Please Enter the First Number  = "))
num2 = int(input("Please Enter the second number = "))

sub = num1 - num2
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))

其他产出很少

Please Enter the First Number  = 11
Please Enter the second number = 43
The Result of subtracting 43 from 11 = -32

Please Enter the First Number  = 99
Please Enter the second number = 23
The Result of subtracting 23 from 99 = 76

Python 编程使用函数减去两个数。

def subtractTwoNum(a, b):
    return a - b

num1 = int(input("Please Enter the First Number  = "))
num2 = int(input("Please Enter the second number = "))

sub = subtractTwoNum(num1, num2)
print('The Result of subtracting {0} from {1} = {2}'.format(num2,num1,sub))
Please Enter the First Number  = 12
Please Enter the second number = 49
The Result of subtracting 49 from 12 = -37

Please Enter the First Number  = 70
Please Enter the second number = 37
The Result of subtracting 37 from 70 = 33

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。