In [ ]:
# from random import randint #imports randint
from os import system #imports system
wins = 0 #Creates a variable for how many times the user wins
rounds = 0 #Creates a variable for how many rounds that the user played
def clear_output(): #Making a function to clear sreen
system("cls") #This is the code to clear the screen when running the program on windows
def play_game(givin_attempts): #Making a function to play the game and gets the number of attempts the player get
global wins #Lets use wins in the function
global rounds #Lets use wins in the function
clear_output() #Clears the output
rounds =+ 1 #Adds one to rounds
number = randint(0,0) #Picks a random number from 1-1000 and makes it a variable
for attempt in range(1,givin_attempts+1): #Starts a for loop and loops 10 times with attempt being the users attempts
print("attempts# {}".format(attempt)) #Prints the users current attempt
guess = int(input("Guess a number: ")) #Ask them to guess a number
if guess != number: #If they did not guess the number
if attempt == givin_attempts: #If that was the users last attempt
print("") #Prints a blank for organization
print("Game over. The number was {}".format(number)) #Tells the user game over and the number
exit() #Brings the user to the exit screen
break #Ends this function
if guess >number: #If their guess it higher than the number
print("The number is less than {}".format(guess)) #Tell them the number is less than there guess
elif guess < number:#If there guess is less than the number
print("The number is higher than {}".format(guess)) #Tell them the number higher than their guess
if guess == number: #If they guess the number
wins += 1 #We give them a point tords wins
print() #Print a blank for organization
print("You win!") #Print you win
if wins == 3: #If they reach three wins
print("You unlocked a new difficulty!") #We tell them they unlocked a new difficulty
if givin_attempts == 1: #Checking if they are on insane mode
print("Whoa")
exit() #Brings the user to the exit screen
break #Ends this function
def exit(): #Making a function to ask the user if they want to player again or exit
print("Do you want to play again?") #Ask the user if they want to play again
again = input("y for yes or n for no: ") #Giving them the input to make a choice
if again == "y": #If they said yes
select_Difficulty() #We run the play_game again
elif again == "n": #If they say no
clear_output() #Clears the screen
print("Results: {} wins and {} rounds".format(wins, rounds)) #Give the user's result of wins and rounds
print("Goodbye.") #Prints goodbye
input("Press enter to quit") #Makes the user press enter to quit
clear_output() #Clear screen
def select_Difficulty(): #A function to choice a difficulty
global wins#Lets use wins in the function
clear_output()#Clears the screen
print("Select from the follow modes:")#Tells the user to pick a mode
print() #Print a blank for organization
print("Type 1 for easy 25 attempts") #Tells them type 1 for easy with 25 attempts
print("Type 2 for normal 10 attempts{}".format("(Recommend for new players)")) #Tells them type 1 for easy with 10 attempts
print("Type 3 for hard 5 attempts") #Tells them type 1 for easy with 5 attempts
if wins < 3: #If they have less than 3 wins
print("Locked. Win 3 three rounds to unlock") #We tell them the the mode is locked and they need to get three wins
else: #Else
print("Type 4 for insane 1 attempt{}".format("(Good luck. You will need it!)")) #We tell them its now a option
print() #Clear screen
choice = input("Pick a difficulty:") #Make the user pick a difficulty
if choice == "1": #If they pick easy
play_game(25) #We give them 25 attempts
elif choice == "2": #If they pick normal
play_game(10) #We give them 10 attempts
elif choice == "3": #If they pick hard
play_game(5) #We give them 10 attempts
elif choice == "4" and wins >= 3: #If they pick insane and have at least three wins
play_game(1) #We give them 1 attempts
else: #Else
select_Difficulty() #We make them pick again
def menu(): #A function for the menu
clear_output() #Clear screen
print("Welcome to Guess The Number!") #Print welcome
print("You have to guess a number 1-1000") #Print the goal
print("Good luck.") #Print good luck
choice = input("Press y for yes or n for no: ") #We ask them for a answer
if choice == "y": #If we say yes
select_Difficulty() #We make them send them to select_Difficulty
elif choice == "n": #If they say no
clear_output() #Clear screen
print("Goodbye.") #Say goodbye
input("Press enter to quit") ##Makes the user press enter to quit
clear_output() #Clear screen
else: #Else
menu() #We make them pick again
if __name__ == "__main__": #Prevents librarys from taking control
menu() #We send them to menu