Reputation: 45
So when i was programming a simple hangman game for fun, because of the beginner i am i still need help on things:
I want my algorithm to test whether an input has only one character for example:
while True:
x=str(input())
#code checking wheather it is only one character, if it is
character break and stop the loop,
otherwise repeat the input
Let's say my secret word is 'billy'
I would want to know how to how to check whether this one letter input has the same letter as any of those in the secret word. for e.g
if x *code checking if the input has a same letter as the secret word*:
#carry on program
If you can help me with either of these two problems you'd be a lifesaver!
Upvotes: 2
Views: 115
Reputation: 287
You could use if in when checking. So you get the input and then you would use code like the following:
if x in secret_word:
#carry on with the program
To check for it having one character use len. So
if len(x)==1:
#carry on
Upvotes: 5