Python Compute the Sum of Two Numbers
This simple Python program demonstrates how to compute the sum of two numbers. We define two variables to store the numbers and then use the addition operator to compute their sum.
Example
Define two numbers
num1
=
5
num2
=
10
Compute the sum of the two numbers
sum
=
num1 + num2
Output result
(
"The sum of the two numbers is:"
,
sum
)
Code analysis:
num1 = 5andnum2 = 10: These two lines define two variablesnum1andnum2, and assign them the values 5 and 10 respectively.sum = num1 + num2: This line computes thenum1andnum2sum of and stores the result in the variablesumit.print("两个数字的和是:", sum): This line prints the computed result.printThe function displays information on the screen; here it displays the string "The sum of the two numbers is:" and the variablesumvalue.
Output result:
两个数字的和是: 15
Python3 Examples