I wrote the code below:
try:
nums=input("Write a name:")
print (nums)
except ValueError:
print ("You didn't type a name")
The problem is that even the user enter a number the program prints it `
You can use the builtin Python function type() to determine the type of a variable.
input() will return always a string.You can use regex like this example:
import re
while True:
try:
name = input('Enter your name: ')
validate = re.findall(r'^[a-zA-Z]+$', name)
if not validate:
raise ValueError
else:
print('You have entered:', validate[0])
break
except ValueError:
print('Enter a valid name!')
a -> z and A -> Z So, for example foo123 will throw ValueError exception.