0
hi guys,how to show error when a user input the name with number,it is possible solve it without using def function?
3 Réponses
+ 4
try:
name = input('Enter name > ')
for n in name:
if n.isdigit():
raise ValueError
print('Hello ' + name + '!')
except ValueError:
print('NO NUMBERS')
+ 4
Here is a sample that works without try: except:
inp = input('enter name: ')
res = ''.join([i for i in inp if not i.isdigit()])
print('correct') if len(res) == len(inp) else print('not correct')