'Guessing game not working and not printing finish_game (Python)
Here is my code:
import time
secret_word = 'secret' or 'Secret'
y = 'yes'
n = 'no'
def try_again():
input("Try again: ")
if input(secret_word):
finish_game()
def finish_game():
print("Nice job! Try again?")
time.sleep(0.5)
input("Y/N")
if input(y):
new_game()
if input(n):
print("You can always try later!")
else:
print("Hmm.. Don't recognize that. Try doing Y/N.")
def new_game():
print("Welcome to Guess the Word!")
time.sleep(1)
print("You have unlimited tries to guess a word!")
time.sleep(1)
print("Ready?")
time.sleep(1)
input("Guess your word here: ")
if input(secret_word):
finish_game()
new_game()
Every time I run, I input my secret word and just get "secret" in return. After that, the game ends. Any help to make it print finish_game?
Solution 1:[1]
This answer will get past not finishing the game, so you can work on the remaining game logic.
import time
secret_word = 'secret' or 'Secret'
y = 'yes'
n = 'no'
def try_again():
input("Try again: ")
if input(secret_word):
finish_game()
def finish_game():
print("Nice job! Try again?")
time.sleep(0.5)
input("Y/N")
if input(y):
new_game()
if input(n):
print("You can always try later!")
else:
print("Hmm.. Don't recognize that. Try doing Y/N.")
def new_game():
print("Welcome to Guess the Word!")
time.sleep(1)
print("You have unlimited tries to guess a word!")
time.sleep(1)
print("Ready?")
time.sleep(1)
answer = input("Guess your word here: ")
# if input(secret_word): # Replace with the following.
if answer in ['secret', 'Secret']: # a list of acceptable
# answers
finish_game()
else:
finish_game()
new_game()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carl_M |
