Q&A CBSE12A-2016-B02B #6288
Question:
What will be the output of the following python code considering the following set
of inputs?
AMAR
THREE
A123
1200
Also, explain the try and except used in the code.
Start=0
while True:
try:
Number=int(raw_input(“Enter Number”))
break
except ValueError:
Start=Start+2
print(“Reenter an integer”)
print(Start)
Answer:
Output:
Enter Number AMAR
Reenter an integer
Enter Number THREE
Reenter an integer
Enter Number A123
Reenter an integer
Enter Number 1200
6
Explanation: The code inside try makes sure that the valid number is entered by the user. When any input other than an integer is entered, a value error is thrown and it prompts the user to enter another value.
