Python 基础知识:如何添加数字
为了演示,我们将使用算术运算符将两个数字相加。这个简单的 Python 程序允许用户输入两个值,然后将这两个数字相加并显示变量总和。
Python 代码:-
#python 程序将两个数字相加
number1 = input(" Enter the First No: ")
number2 = input(" Enter the Second No: ")
#using arithmetic + Operator to add two numbers
sum = float(number1) + float(number2)
print('The sum of {0} and {1} is {2}'.format(number1, number2, sum))