1.

What will be the output of the following python code considering the following set of inputs? AMAR THREE A1231200 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)

Answer»

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.



Discussion

No Comment Found