-2
q = []
num = ["1","2","3","4","5","6","7","8","9","0"]
while True:
    dat = float(input("Enter Name: "))
    if dat == "*":
      print(q.pop(0))
    if dat in num :
    break
    else:
      q.append(dat)

#the program only terminates when inputted 0 to 9 numbers but I want it to terminate if any numbers are inputted.

0

2 Answers 2

4

Use .isdigit(). Try in this way-

q = []
#num = ["1","2","3","4","5","6","7","8","9","0"]
while True:
    dat = input("Enter Name: ")
    if dat == "*":
      print(q.pop(0))
    if dat.isdigit() :
        break
    else:
      q.append(dat)
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of checking if dat is a digit, should then check if any of its characters is a digit:

q = []
somedigit = False
while True:
    dat = input("Enter Name: ")
    if dat == "*":
      print(q.pop(0))
    for element in dat:
         if element.isdigit():
             somedigit = True
             break
    if somedigit == True:
        break
    else:
      q.append(dat)

Other way is to check the function isalpha:

q = []
while True:
    dat = input("Enter Name: ")
    if dat == "*":
      print(q.pop(0))
    if not dat.isalpha():
      break
    else:
      q.append(dat)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.