-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.

Studyante
  • 29
  • 4

2 Answers2

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)
SAI SANTOSH CHIRAG
  • 2,046
  • 1
  • 10
  • 26
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)
robbinc91
  • 548
  • 6
  • 14