python 3.x - Checking if a variable contains spaces and letters -


i trying make program asks name reject input if doesn't contain letters/spaces. however, seems reject spaces numbers , symbols.

print("welcome basic arthmetics quiz.") print("what name?") name=input() if not name.isalpha()or name not in(str(" ")):     print('please enter letters name!')     while not name.isalpha()or name in(str(" ")):         v=1         print('please enter name again.')         name=input()         if name.isalpha()or name not in(str(" ")):             v=0         else:             v=1 

where have gone wrong?

this looks awful lot homework.

your test name not in(str(" ")), should written name not in " ", tests whether name 1 of {"", " "}.

it easiest test name 1 char @ time, per-char condition like

char.isalpha() or char == ' ' 

combine all , generator expression test chars of name.

the actual implementation, proper code flow (you don't use v, perform test thrice, , call input() twice, of unacceptable) left exercise.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -