Add Two Numbers in Python
This tutorial shows how to add two numbers in Python. We'll take both static and user input examples using integers and floats (Python uses float for decimal/double).
यह ट्यूटोरियल Python में दो numbers को जोड़ना सिखाता है। हम static और user input दोनों examples को integer और float (decimal/double) values के साथ दिखाएंगे।
Example 1: Add Two Integers (Static)
a = 10
b = 20
sum = a + b
print("Sum =", sum)
Output:
Sum = 30
Adds two integer values directly.
दो integers को सीधे जोड़ता है।
Example 2: Add Two Float Values (Static)
x = 12.5
y = 7.3
result = x + y
print("Result =", result)
Output:
Result = 19.8
Adds two float (decimal) values.
दो decimal numbers को जोड़ता है।
Example 3: Add Two Numbers from Keyboard (int)
a = int(input("Enter first number: ") )
b = int(input("Enter second number: ") )
print("Total =", a + b)
Output:
Enter first number: 5 Enter second number: 15 Total = 20
Takes two integers from user and adds.
यूज़र से दो integers लेता है और जोड़ता है।
Example 4: Add Two Numbers from Keyboard (float)
x = float(input("Enter first decimal: ") )
y = float(input("Enter second decimal: ") )
print("Sum =", x + y)
Output:
Enter first decimal: 4.5 Enter second decimal: 2.5 Sum = 7.0
Reads float values from user input.
यूज़र से दो decimal values लेकर जोड़ता है।