Question: Write a Python Program to Store two numbers in variables and print their sum.
Example 1:
# Step 1: Store number 1st in varable num1
num1 = 10
# Step 2: Store number 2nd in variable num2
num2 = 20
# Step 3: Calculate their sum
sum_of_numbers = num1 + num2
# Step 4: Print the sum
print(f"The sum of {num1} and {num2} is {sum_of_numbers}")
Output:
The sum of 10 and 20 is 30
Example 2:
# Step 1: Store number 1st in varable num1 as user input
num1 = float(input("Enter the first number: "))
# Step 2: Store number 2nd in varable num2 as user input
num2 = float(input("Enter the secnod number: "))
# Step 3: Calculate their sum
sum_of_numbers = num1 + num2
# Step 4: Print the sum
print(f"The sum of {num1} and {num2} is {sum_of_numbers}")
Output:
Enter the first number: 20
Enter the second number: 30
The sum of 20.0 and 30.0 is 50.0
Notebook Example:
These Python programs are created by experienced programmers to aid students in learning Python. We are here to make your learning experience as interactive and informative as possible. If you have questions or need more clarification, feel free to ask. Happy coding!
Please support independent contributors like Code2care by donating a coffee.
Buy me a coffee!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
Thanks for your feedback! If you have time, please provide details by selecting options below.
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!