What will be the output of the following python code considering the following set of inputs?
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 (“Re-enter an integer”) Print (start)
2 Answers
Output:
Enter Number AMAR
Re-enter an integer
Enter Number THREE
Re-enter an integer
Enter Number A123
Re-enter an integer
Enter Number 12006
Explanation : The code inside try makes sure that the valid number is entered by the user. When any input other an integer is entered, a value error is thrown and it prompts the user to enter another value.
Output is below
2 Re-Enter Number
10 Re-Enter Number
5 Input = Number
3 Input = number
Try and except are used for handling an exception in the Python code.