0

How to find a letter in a string

so i'm making a output version of hangman just as a fun project and i did test of some code that will compare an input string to another string and print yes or no if it is or not in the guess is in the string but no happen what i enter it says no. Here's my code of the function: def LetterCheck(): Guess = str(input()) if Guess == "" or Guess == " ": print("Enter a letter") else: if Guess in Word: print("yes") else: print("no")

12th Feb 2020, 7:31 AM
Sheepeto
Sheepeto - avatar
5 Answers
+ 8
BTW you never need to say str(input()) - it's redundant. Every input is always a string. Just say input() 😊
12th Feb 2020, 8:19 AM
David Ashton
David Ashton - avatar
+ 4
u did not define Word in function
12th Feb 2020, 7:36 AM
Oma Falk
Oma Falk - avatar
+ 2
global Word in your function does it but better make it a parameter
12th Feb 2020, 8:02 AM
Oma Falk
Oma Falk - avatar
+ 1
oh thanks i originally did define it outside of the function i guess having multiple functions for different things while using it in both doesn't work
12th Feb 2020, 7:46 AM
Sheepeto
Sheepeto - avatar
0
Yeah I know. it's just a habit of mine to put the type of input I want it to be so I don't get confused or something, i guess I comments also allows me to do that
12th Feb 2020, 6:50 PM
Sheepeto
Sheepeto - avatar