+ 1
Whys this not working?
Only letters are allowed as input, i intentionally typed in a number but didnt get wrong https://code.sololearn.com/c7PoEd2A8I1X/?ref=app
7 Respuestas
+ 5
Lenoname
Raise exception only when input is not alpha
try:
a = input()
b = a.isalpha()
if not b:
raise Exception
except Exception:
print("wrong")
You can also do this if you don't want numeric values
try:
a = input()
print (int(a))
except Exception:
print("Enter only string")
+ 2
You need an if for isalpha, so something like this:
try:
a = input()
b = a.isalpha()
if not b:
raise Exception
except Exception:
print("wrong")
But you really don't need the try except for this.
+ 1
The value of b will be TRUE or FALSE. But it will not be an exception.
+ 1
You need something like this:
a = input()
b = a.isalpha()
if b:
print('Good')
else:
print('Wrong input')
+ 1
I’m trying to use exceptions
0
try:
a = input()
b = a.isalpha()
raise Exception
except Exception:
print("wrong")
??like this? Printed wrong every time even when i used alphabets
0
Paul how about this one?⬆️