+ 2
How to allow only letters as input?
A = input(âyour input: â) If A == None: print(âwrong try againâ) This wont work
10 Respostas
+ 9
Lenoname you can use the .isalpha() method and try-except logic.
https://www.w3schools.com/JUMP_LINK__&&__python__&&__JUMP_LINK/ref_string_isalpha.asp
https://www.w3schools.com/python/python_try_except.asp
+ 7
try-except:
from string import ascii_letters
try:
a = input()
assert all(c in ascii_letters for c in a)
except:
print("Wrong, try again")
isalpha():
a = input()
if a.isalpha():
print("Correct!")
else:
print("Wrong")
+ 5
isalpha() method or try-except statement, not both
+ 5
Lenoname ,
what about this:
while not (inp := input()).isalpha():
print("wrong input - try again: ")
print("all chars are letters:", inp)
it does not handle spaces, but this was not mentioned
+ 3
đźđłSATYAPRAKASHđźđł that accomplishes literally nothing. All input is string in python.
+ 2
try:
a = input()
assert a.isalpha()
print(a)
except:
print("wrong")
+ 2
take input
while incorrect input:
ask again
if the test is really bulky you might instead wanna do:
while True:
take input
if correct input:
break
else:
complain some to the user
0
Simon Sauter this didnt work though⊠any suggestions?
https://code.sololearn.com/c7PoEd2A8I1X/?ref=app
- 1
Try-except without isalpha?Could u give an example please
- 2
...All input is string in python.