Skip to content

Commit e4a64ac

Browse files
authored
Merge pull request #90 from MeetMangukiya7/main
Add Two Numbers
2 parents ad293fa + 256c8fb commit e4a64ac

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

0002/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Adding Two numbers in Python
2+
# Program 01
3+
In the program, we've used the + operator to add two numbers.
4+
5+
# Program 02
6+
In this program, we asked the user to enter two numbers and this program displays the sum of two numbers entered by user.
7+
8+
We use the built-in function input() to take the input. Since, input() returns a string, we convert the string into number using the float() function. Then, the numbers are added.
9+
10+
Alternative to this, we can perform this addition in a single statement without using any variables.

0002/add_two_number.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 1: Add Two Numbers
2+
# This program adds two numbers
3+
4+
num1 = 1.5
5+
num2 = 6.3
6+
# Add two numbers
7+
sum = num1 + num2
8+
# Display the sum
9+
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
10+
11+
# 2: Add Two Numbers With User Input
12+
# Store input numbers
13+
num1 = input('Enter first number: ')
14+
num2 = input('Enter second number: ')
15+
# Add two numbers
16+
sum = float(num1) + float(num2)
17+
# Display the sum
18+
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))

0 commit comments

Comments
 (0)