0

I have stucken on Exception handling in python

This is the problem i need to solve. As a beginner i have tried a lot but can't figure out the problem. Please help to clear it.Thanks in advance. """We need to create a program that allows users to create their own PIN codes for their bank cards. Each PIN code consists of digits. Complete the program so that when the user enters a character, the program stops and outputs "Please enter a number" and when the user enters only digits, the program outputs "PIN code is created". """ Sample Input 44a5 Sample Output Please enter a number

20th Mar 2025, 4:25 PM
Mahmodul Islam Sourav
Mahmodul Islam Sourav - avatar
3 Answers
+ 5
Show your code
20th Mar 2025, 5:10 PM
Lisa
Lisa - avatar
+ 1
What!??
22nd Mar 2025, 2:34 PM
Kiwi
Kiwi - avatar
0
Mahmodul Islam Sourav For the specific problem you mentioned, you don't need exception handling. You can use the built-in Python String method isdecimal( ) to check if your sample input is all 0-9 or not, and respond accordingly. If you must use exceptions, they follow the below basic format: try: # Indented code block # which might generate exception. # Can generate exception yourself # with 'raise <exception>("msg")' except: # Indented code block # to handle exception. # Can have multiple except blocks # to handle different exceptions. else: # OPTIONAL indented code block # to handle if no exception occurs. finally: # OPTIONAL indented code block # to always run whether exception # occurs or not. You might check your input for letters and raise an exception if any found. Then your except block would handle letting the user know.
22nd Mar 2025, 4:36 AM
Shardis Wolfe