0

TypeError: 'in <string>' requires string as left operand, not int

ERROR message: Traceback (most recent call last): File "C:/Users/Brittany/AppData/Local/Programs/Python/Python36-32/Hangman_2.0.py", line 17, in <module> if guessed_letter in random_secret_word: TypeError: 'in <string>' requires string as left operand, not int CODE: import random play_game = input('Play game?' '').title() while play_game == 'Yes': print ('Welcome to Hangman!') secret_words = ('Solo Learn', 'C', 'Python', 'C++',\ 'Ruby On Rails', 'Ruby', 'Java', 'Javascript',\ 'Html', 'C#', 'Objective C') random_secret_word = random.choice(secret_words) print ('Guess letter!') guessed_letter = input() letters = random_secret_word.index(random_secret_word) correct = guessed_letter in random_secret_word all_correct = letters wrong = guessed_letter not in random_secret_word for guessed_letter in range(0,15): if guessed_letter in random_secret_word: print ('Correct letter!') else: print ('Wrong') if all_correct: print (random_secret_word) else: print ('You lose!')

3rd Jul 2017, 8:59 PM
Iris Eye
Iris Eye - avatar
3 Antworten
0
That didn't fix my problem because i need to repeat the loop and input 15 times
3rd Jul 2017, 9:45 PM
Iris Eye
Iris Eye - avatar