python - Looping with a while statement while reading a string for an integer -


i need encasing the:

if any(c.isdigit() c in name): print("not valid name!") 

inside of while statement. pretty reads input "name" variable , sees if there's integer in it. how use in while statement? want if user inputs variable input, print out string above , loop , ask user name again until enter in string no integer, want break. help?

print("hello there!") yn = none while yn != "y":     print("what name?")     name = raw_input()     if any(c.isdigit() c in name):         print("not valid name!")     print("oh, name {0}? cool!".format(name))     print("now how old you?")     age = raw_input()     print("so name {0} , you're {1} years old?".format(name, age))     print("y/n?")     yn = raw_input()     if yn == "y":         break     if yn == "n":         print("then here, try again!") print("cool!") 

use while true , break end loop when valid name has been entered:

while true:     name = raw_input("what name? ")     if not any(c.isdigit() c in name):         break     print("not valid name!") 

this easier first initializing name invalid using any() expression in while test.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -