0
PIN number challenge
Write a program for making PIN numbers. When a user inputs digits(numbers e.g. 5555) it's accepted and "PIN is created" is displayed but if the input is not made up of values only ( e.g. 56gg7) the message "PIN not created" is displayed. I'm using exceptions and this what my code pin = input() try: print ( "PIN number created") except: print ( "PIN not created") Some answers are correct while others are wrong and they show " PIN number created "
3 Antworten
+ 1
Your code will always display "PIN number created", was it really difficult for you to check it yourself in Python before asking this question?
0
"""You aren't catching any error or throwing any in try block , maybe revise that topic again !
Basically question asks that pin should contain numbers only . For that you can google and try various methods . The one i found is
isdigit() method which returns true if the value is integer . """
a=input()
print(a.isdigit())
Also going with what you have written, just add the following line in try block above "print("pin.... ".
pin=int(pin)
And it should work fine as well!
0
Put
pin = int(input())
inside try block .