samedi 4 avril 2015

How can I tell if a string only contains letter AND spaces

I'm having trouble figuring out the above question and have a felling I should be testing every character with "for character in string" however I cant really figure out how that would work


This is what I have now but I know it doesnt work as intended because it only allows me to test letters but I also need to know spaces so for example " MY dear aunt sally" should say yes contains only letters and spaces



#Find if string only contains letters and spaces
if string.isalpha():
print("Only alphabetic letters and spaces: yes")
else:
print("Only alphabetic letters and spaces: no")

Aucun commentaire:

Enregistrer un commentaire