CBSE Class 11 Computer Science Question 86 of 98

Python Programming Fundamentals — Question 48

Back to all questions
48
Question

Question 35

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.

Solution
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
Answer