- 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...
22 Respuestas
+ 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")
+ 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")
+ 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.
+ 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")
+ 2
pin = input()
try:
pin = int(pin)
print("PIN code is created")
except ValueError:
print("Please enter a number")
+ 1
Jan Markus its not working
and also i did not understand...
+ 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")
+ 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")
+ 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")
0
Jan Markus can you explain f in the try portion
of 3rd
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
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")
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")
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")
0
pin = input()
try:
pin = int(pin)
print("PIN code is created")
except ValueError:
print("Please enter a number")
0
correct code
try:
pin = int(input())
print('PIN code is created')
except ValueError:
print('Please enter a number')
0
pin = input()
try:
#your code goes here
pin = int(pin)
print("PIN code is created")
except (ValueError, TypeError):
print("Please enter a number")
0
pin = input()
try:
digits=(int(pin))
print("PIN code is created")
except ValueError:
print(" Please enter a number")
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
0
pin = input()
try:
#your code goes here
int(pin)
print ("PIN code is created")
except ValueError:
#and here
print ("Please enter a number")