CBSE Class 11 Informatics Practices
Question 51 of 52
Python Programming Fundamentals — Question 51
Back to all questions 51
Question Write a program to read three numbers in three variables and swap first two variables with the sums of first and second, second and third numbers, respectively.
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
print("The three number are", a, b, c)
a, b = a + b, b + c
print("Numbers after swapping are", a, b, c)Enter first number: 10
Enter second number: 15
Enter third number: 20
The three number are 10 15 20
Numbers after swapping are 25 35 20
a
=
int
(
input
(
"Enter first number: "
))
b
=
int
(
input
(
"Enter second number: "
))
c
=
int
(
input
(
"Enter third number: "
))
print
(
"The three number are"
,
a
,
b
,
c
)
a
,
b
=
a
+
b
,
b
+
c
print
(
"Numbers after swapping are"
,
a
,
b
,
c
)
Output
Enter first number: 10
Enter second number: 15
Enter third number: 20
The three number are 10 15 20
Numbers after swapping are 25 35 20