0

I'm trying to ask for someone's name but I'm not sure how to tell if there is a number in there answer. code:

 name1ask = ("wrong")
 while name1ask != ("right"):
   name1 = input("What's player 1's name?") 
   spaces = " " in name1
   if type(name1) != str : #here I try to check if its a number(integer)
      print("Words only") 
   elif len(name1) > 10:
      print("Names under 10 letters only")
   elif spaces == True:
      print("No spaces")
   else:
      print("Welcome " + name1)
      name1ask = ("right")

2 Answers2

0

You can do any check in your while loop to check if any of your letters in name is a digit and repeat the input if so:

name1 = '1'
while any(x.isdigit() for x in name1):
    name1 = input("What's player 1's name? ")

In your case, you can replace these lines of code:

if type(name1) != str : # here I try to check if its a number(integer)
    print("Words only")

with:

if any(x.isdigit() for x in name1):
    print("Words only")
Austin
  • 25,759
  • 4
  • 25
  • 48
  • Follow up question, how would I check for symbols? Thanks for your previous answer – Lennox Nilson Mar 24 '20 at 08:22
  • That almost changed wholly from your question title and any answer I provide further will deviate further readers unless you modify your question. – Austin Mar 24 '20 at 08:45
0

To check if the string name contains a number

any([str(element) in name for element in [0,1,2,3,4,5,6,7,8,9]])
Suraj
  • 2,253
  • 3
  • 17
  • 48