This question already has an answer here:
I want the output of my program to say that if you have an input like “hey there!" The letters and spaces check should say “no” because of the exclamation point, or "hey" it should also read no because there are no spaces, but if the user inputs "hey there" it will say yes only spaces and letter. However, I am stuck because I can't get it to read no when I have the "!"
only_alpha = False
only_space = False
other_characters = False
for character in string:
if character.isalpha():
only_alpha = True
if character == " ":
only_space = True
else:
other_characters = True
if only_alpha == True and only_space == True:
print("Contains only letters and spaces: yes")
elif other_characters == True:
print("Contains only letters and spaces: no")
else:
print("Contains only letters and spaces: no")
Aucun commentaire:
Enregistrer un commentaire