Table of Contents
Example Description
Learn how to find the sum of two numbers using Python with this straightforward code example. Add num1 and num2 to calculate the result.

Introduction:

Discover the Python magic of finding the sum of two numbers! This code snippet showcases how to add 10 and 20 (num1 and num2) effortlessly, resulting in the sum displayed as the output. Unlock the power of Python’s simple yet essential arithmetic operation with this concise and enlightening example.

Code:

num1 = 10
num2 = 20
result = num1 + num2
print(result)

Logic:

  1. Assign the value 10 to the variable “num1” to represent the first number.
  2. Assign the value 20 to the variable “num2” to represent the second number.
  3. Calculate the sum of the two numbers by adding the values of “num1” and “num2” together and store the result in the variable “result.”
  4. Print the calculated result using the “print” function.

Output:

In summary, the code adds the values of “num1” and “num2” (10 and 20, respectively) and displays the sum, which would be 30.

>> 30