I want to create a program that allows users to create their own pin for bank account. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

I want to create a program that allows users to create their own pin for bank account.

pin = input() try: pin=int(input()) print("PIN code is created") except ValueError: print ("please enter a number") I tried but its not working...

29th Oct 2020, 1:02 PM
Rahul Prasad
Rahul Prasad - avatar
22 Answers
+ 6
The hint at the bottom of the page tells us that if we call the "int" function on a variable that is not an interger, there will be a error. maybe its the "value" error required to raise the "except" block. pin = input() try: pin = int(pin) print("PIN code is created") except ValueError: print("Please enter a number")
7th Apr 2021, 4:23 PM
Ben S.
+ 3
Hello @everyone Was just thinking how to solve this code. And i just realized that if i Put my input before "try:" command it doesn't affect my code, i dont know if i really explained my self there. but im leaving you my first try that gives me and error even tho i have "except ValueError: " in it and the second one that does work well. Hope i could help you. Have a nice day INCORRECT ONE pin = int(input()) try: #your code goes here print("PIN code is created") except ValueError: #and here print("Please enter a number") CORRECT ONE try: pin = int(input()) #your code goes here print("PIN code is created") except ValueError: #and here print("Please enter a number")
29th May 2021, 11:28 AM
Vladimir Pavlenko
Vladimir Pavlenko - avatar
+ 2
Just finished this in a maybe unorthodox way, but the code that worked for me was: pin = input() try: int(pin) / 1 print("PIN code is created") except ValueError: print("Please enter a number") If the pin is not made up of integers it prints the error. Might be smart, might be problematic, but it worked.
1st May 2021, 6:20 AM
Martins
+ 2
Rahul Prasad , to do this task with a try except is absolutely ok. but it could also be done like this: ▪︎instead of using try ... you can check if the input contains only numbers ▪︎the user can decide to exit the PIN input procedure by typing like "x" ▪︎i also put the code in a while loop, so that the user can try the input again when he fails: while True: pin = input("Enter PIN number or x to exit: ") if pin.isdigit(): print("PIN code is created") break elif pin.lower() == "x": print("Terminating input of PIN") break else: print("Please enter a correct number")
2nd May 2021, 5:31 PM
Lothar
Lothar - avatar
+ 2
pin = input() try: pin = int(pin) print("PIN code is created") except ValueError: print("Please enter a number")
12th Jul 2021, 10:23 AM
Constantine Tvalashvili
Constantine Tvalashvili - avatar
+ 1
Jan Markus its not working and also i did not understand...
29th Oct 2020, 1:18 PM
Rahul Prasad
Rahul Prasad - avatar
+ 1
pin = input() try: #your code goes here int(pin) print("PIN code is created") except ValueError: #and here int() print("Please enter a number")
27th Jan 2022, 5:07 PM
Arbab Ansari
Arbab Ansari - avatar
+ 1
pin = input() try: #your code goes here int(pin) == int print ("PIN code is created") except ValueError: #and here print("Please enter a number")
11th Dec 2022, 5:27 AM
Noob X Neon
Noob X Neon - avatar
+ 1
pin = input() try: #your code goes here int(pin) == True print("PIN code is created") except ValueError: #and here print("Please enter a number")
16th Apr 2023, 6:17 PM
AMINE MOUTAOUAKKIL
0
Jan Markus can you explain f in the try portion of 3rd
29th Oct 2020, 1:13 PM
Rahul Prasad
Rahul Prasad - avatar
0
Jan Markus its a code coach problem still i did not now about f string... 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
29th Oct 2020, 1:26 PM
Rahul Prasad
Rahul Prasad - avatar
0
# I think this works, you need exact same letters cases, and only output.... try: pin=int(input()) print("PIN code is created") except : print ("Please enter a number")
29th Oct 2020, 2:01 PM
Jayakrishna 🇮🇳
0
I got 2 out of 4 correct with this code but can't make the other two right. so this code is partially right.. You can try. pin = input() try: type(pin)==int print("PIN code is created") except: print("please enter a number")
19th Mar 2021, 11:09 AM
Somnath Das
Somnath Das - avatar
0
pin = input() try: #your code goes here pin = int(pin) print("PIN code is created") except ValueError: #and here print("Please enter a number")
26th Jun 2021, 8:41 PM
Muhammedh Ikram
Muhammedh Ikram - avatar
0
pin = input() try: pin = int(pin) print("PIN code is created") except ValueError: print("Please enter a number")
28th Jun 2021, 1:23 PM
Lokendra Gupta
Lokendra Gupta - avatar
0
correct code try: pin = int(input()) print('PIN code is created') except ValueError: print('Please enter a number')
16th Jul 2021, 7:51 AM
Hugues Rodrigue Tha Andela
Hugues Rodrigue Tha Andela - avatar
0
pin = input() try: #your code goes here pin = int(pin) print("PIN code is created") except (ValueError, TypeError): print("Please enter a number")
21st Aug 2021, 9:38 AM
Shree Harini
Shree Harini - avatar
0
pin = input() try: digits=(int(pin)) print("PIN code is created") except ValueError: print(" Please enter a number")
10th Jan 2022, 8:55 AM
Shahad Al-Shama
0
try: #your code goes here pin = int(input()) if pin not in [0-9]: print("PIN code is created") except ValueError: #and here print("Please enter a number") #You can use like this using if condition
6th Jun 2022, 6:21 PM
Abdulahi Redwan
Abdulahi Redwan - avatar
0
pin = input() try: #your code goes here int(pin) print ("PIN code is created") except ValueError: #and here print ("Please enter a number")
15th Jun 2022, 7:17 AM
Oluwaseyi Abiodun Fadahunsi
Oluwaseyi Abiodun Fadahunsi - avatar