from time import *
import threading
def countdown():
global my_timer
my_timer = 5
for x in range(5):
my_timer = my_timer - 1
sleep(1)
print("Time is up! Sorry!")
countdown_thread = threading.Thread(target = countdown)
countdown_thread.start()
while my_timer > 0:
again="yes"
while again=="yes":
difficulty = input("Difficulty? easy, medium or hard? ")
if difficulty == "easy":
player1=int(input("Player 1 please enter a number from 1 to 99: "))
guess= eval(input("Player 2 please enter your guess between 1 and 99 "))
count=1
lives=int(7)
if guess==player1:
print("You rock! You guessed the number in" , count , "tries!")
while guess !=player1:
count+=1
if lives == 1:
print(" No more lives, GAME OVER")
break
elif guess > player1 + 10:
print("Too high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1 - 10:
print("Too low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess > player1:
print("Getting warm but still high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1:
print("Getting warm but still Low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
if guess==player1 or lives !=0:
print("You rock! You guessed the number in" , count , "tries!")
if guess == player1 or lives==1:
again=str(input("Do you want to play again, type yes or no "))
if again == "no":
print("Bye")
break
elif again == "yes":
continue
elif difficulty == "medium":
player1=int(input("Player 1 please enter a number from 1 to 199: "))
guess= eval(input("Player 2 please enter your guess between 1 and 199 "))
count=1
lives=int(10)
if guess==player1:
print("You rock! You guessed the number in" , count , "tries!")
while guess !=player1:
count+=1
if lives == 1:
print(" No more lives, GAME OVER")
break
elif guess > player1 + 20:
print("Too high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1 - 20:
print("Too low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess > player1:
print("Getting warm but still high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1:
print("Getting warm but still Low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
if guess==player1 or lives !=0:
print("You rock! You guessed the number in" , count , "tries!")
if guess == player1 or lives==1:
again=str(input("Do you want to play again, type yes or no "))
if again == "no":
print("Bye")
break
elif again == "yes":
continue
elif difficulty == "hard":
player1=int(input("Player 1 please enter a number from 1 to 299: "))
guess= eval(input("Player 2 please enter your guess between 1 and 299 "))
count=1
lives=int(14)
if guess==player1:
print("You rock! You guessed the number in" , count , "tries!")
while guess !=player1:
count+=1
if lives == 1:
print(" No more lives, GAME OVER")
break
elif guess > player1 + 30:
print("Too high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1 - 30:
print("Too low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess > player1:
print("Getting warm but still high!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
elif guess < player1:
print("Getting warm but still Low!")
lives-=1
print("lives remaining: ", lives)
guess = eval(input("Try again "))
if guess==player1 or lives !=0:
print("You rock! You guessed the number in" , count , "tries!")
if guess == player1 or lives==1:
again=str(input("Do you want to play again, type yes or no "))
if again == "no":
print("Bye")
break
elif again == "yes":
continue
I'm unable to make break the loop when my timer comes to an end.
I tried to include if my_timer==0 break
but it doesn't really work for some reason, and the program just continues on.
I'm really confused by this; can you help me to understand?