This is the code that I wrote
` import random
import time
Initial Steps to invite in the game
print ("\n Welcome to THE GAME \n")
name=input("Enter your name:")
print ("Hello " +name+ " May Luck be ever in your favor")
time.sleep(2)
print ("The game is about to start!\n Let's play Hangman!")
time.sleep(3)
def main():
global count
global word
global already_guessed
global length
global play_game
words_to_guess=["January","border","image","film","kids","lungs","plants","damage"]
A loop to re-execute the game when the first round ends:
def play_loop():
global play_game
play_game=input("Do you want to play again? y=yes, n=no \n")
while play_game not in ["y","n","Y","N"]:
play_game=input("Do you want to play again? y=yes, n=no \n")
if play_game=="y":
main()
elif play_game=="n":
print("HAHAH LOOSER. RUN BACK TO YOUR MOMY")
exit()
Initializing all the condition required for the game:
def hangman():
global count
global display
global word
global already_guessed
global play_game
limit = 6
guess = input("This is the Hangman Word: " + display + " Enter your guess: \n")
guess = guess.strip()
if len(guess.strip()) == 0 or len(guess.strip()) >= 2 or guess <= "9":
print("Invalid input stupid, try a letter looser\n")
hangman()
hangman() `
When I try to run it in Jupiter notebook, it works at first, asks you to type in your name, and after that comes back with the following error
TypeError Traceback (most recent call last)
in
140
141
--> 142 hangman()
in hangman()
47 global play_game
48 limit = 6
---> 49 guess = input("This is the Hangman Word: " + display + " Enter your guess: \n")
50 guess = guess.strip()
51 if len(guess.strip()) == 0 or len(guess.strip()) >= 2 or guess <= "9":
TypeError: can only concatenate str (not "function") to str
This is the code that I wrote ` import random import time
Initial Steps to invite in the game
print ("\n Welcome to THE GAME \n") name=input("Enter your name:") print ("Hello " +name+ " May Luck be ever in your favor") time.sleep(2) print ("The game is about to start!\n Let's play Hangman!") time.sleep(3)
def main(): global count global word global already_guessed global length global play_game words_to_guess=["January","border","image","film","kids","lungs","plants","damage"]
A loop to re-execute the game when the first round ends:
def play_loop(): global play_game play_game=input("Do you want to play again? y=yes, n=no \n") while play_game not in ["y","n","Y","N"]: play_game=input("Do you want to play again? y=yes, n=no \n") if play_game=="y": main() elif play_game=="n": print("HAHAH LOOSER. RUN BACK TO YOUR MOMY") exit()
Initializing all the condition required for the game:
def hangman(): global count global display global word global already_guessed global play_game limit = 6 guess = input("This is the Hangman Word: " + display + " Enter your guess: \n") guess = guess.strip() if len(guess.strip()) == 0 or len(guess.strip()) >= 2 or guess <= "9": print("Invalid input stupid, try a letter looser\n") hangman()
main()
hangman() ` When I try to run it in Jupiter notebook, it works at first, asks you to type in your name, and after that comes back with the following error
TypeError Traceback (most recent call last)