How to allow only letters as input?
A = input(”your input: ”) If A == None: print(”wrong try again”) This wont work
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
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")
isalpha() method or try-except statement, not both
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
try: a = input() assert a.isalpha() print(a) except: print("wrong")
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
Try-except without isalpha?Could u give an example please
...All input is string in python.