KnowledgeBoat Logo
|

Informatics Practices

What will be the output produced by the following code fragment?

first = 2
second = 3
third = first * second
print (first, second, third)
third = second * first
print (first, second, third)

Python Funda

1 Like

Answer

2 3 6
2 3 6

Working

  1. first = 2first is assigned the value 2.
  2. second = 3second is assigned the value 3.
  3. third = first * secondthird is calculated as first * second, which is 2 * 3 = 6.
  4. print(first, second, third) ⇒ The print statement outputs 2 3 6, showing the values of first, second, and third.
  5. third = second * firstthird is reassigned with second * first, which is 3 * 2 = 6.
  6. print(first, second, third) ⇒ The second print statement outputs 2 3 6 again, reflecting the updated value of third.

Answered By

3 Likes


Related Questions