PYTHON
Addition of two numbers | Python
Introduction
In this blog post, we'll explore a simple Python program that takes two numbers as input from the user, calculates their sum, and then displays the result. This basic program is often used as an introductory example for understanding user input and arithmetic operations in Python.
Code
# Adding Two Numbers in Python
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Calculate the sum
sum = num1 + num2
# Display the result
print("The sum is:", sum)
Output
Enter the first number: 5
Enter the second number: 7
The sum is: 12
Explanation
1. User Input:
The program prompts the user to enter two numbers.
2. Sum Calculation:
It adds the two input numbers using the + operator and stores the result in the variable sum.
3. Output:
Displays the calculated sum.
Conclusion
This Python program provides a straightforward example of taking user input, performing a basic arithmetic operation, and displaying the result. Understanding these fundamental concepts is essential for anyone starting their programming journey. Feel free to experiment with different input values and observe how the program accurately calculates the sum. Happy coding!
Post a Comment
0 Comments