Thursday , September 19 2024

What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively? y = input() x = input() print(x + y)

Questions BankCategory: Python Essentials 1What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively? y = input() x = input() print(x + y)
What is the output of the following piece of code if the user enters two lines containing 3 and 6 respectively?

y = input()
x = input()
print(x + y)
  • 6
  • 36
  • 3
  • 63

Explanation: It’s a tricky question because of two reasons:

  • Reason one: the input() function converts the data inputted by the user to a string, and the result of adding two strings to each other is gluing them together: “string” + “string” = “stringstring” (concatenation).
  • Reason two: the first user input is assigned to the y variable, while the second to the xvariable. However, they are printed in the reverse order.

More Questions: Python Essentials 1 (PE1) Course Final Test