In [21]:
#####notes
##The program takes a for loop.
##if you looped 15 items it would loop 15 times ( basically takes a number and loops it for x amount of times)
## what it means to (globalize) a variable: it allows the variable to be seen by all functions
## if you see a colon at the end of the python line it, you indent to the next line
## .format(+1) prints out x amount of numbers
## cant have 2 colons?
## .format())
## elif guesses> number of guess (it would see if the number is correct the one you guessed)
#contains your print()
## uses breaks, leave()
## if guess == number of guesses ( it would see if the number is the same), if correct it would say i won.
#Variable +1 then leave and break
## elif guesses < number of gesses( it would tell me to go higher)\


#elif  guess < number of gueses,  tells me to go higher
#prints (number is larger go higher)
#elif guesses > if the number is greater than the computer it would go lower
#prints (number is lower, less)


###if you lose   define leave statement then input()
### system("clear")
### then do the elif 
### totwin +=1
###

#for myvar in range(0,10):
 #   print(myvar)

#the program basically allows you to insert a random number and the program generates its own random number
#for you to guess it and if you get it wrong or right it tells that you win or lose and you get around 10 tries.
In [ ]:
from random import randint #the libary to access other python codes
from os import system

winCount = 0 # This keeps account of all of my wins

def main(): #defining the main option to restart program
    
    input("press enter to start game") #this will allow my program to start the game when "enter" is pressed.
    global winCount # allows "WinCount" to be allowed in the entire program
    
    Num =  randint(0,1000) # a random number from 0 to 1000 
    
    for guess in range (0,10): #this is the amount of attempts that you have
        
        print("attempt {}".format(guess+1)) # prints the number of your current tries
        NumForGuess = int(input("Enter a number =>"))  # allows you to input a number or as your guess.
        if guess == 9 and NumForGuess != Num: #then after you input a number/guess, the program will check to see if the guess matches the computers number.
            
            system("clear")  #clears screen
            print("Sorry the number is actually {}".format(Num)) #if you dont win within on of those 10 tries it prints the actual number, saying that you lost.
            leave() #leaves the function
            break #breaks up the loop
            
        if NumForGuess == Num:  #to see if my number is equal to the computers
        
            system("clear again") #clears screen
            print("you have found the corect answer") #your number is correct
            leave() #leaves function
            break #breaks up this loop
        
        
        elif NumForGuess < Num: # if my number is less than the computer you need to find a number thats higher

            system("clear again") #clears the screen
            print("you have find a number thats higher") #it will say you have to find a number that is higher
        
        
        elif NumForGuess > Num: #if my number is greater than the number it will say it's lower
        
            system("clear again") #clears screen
            print("you have to find a number that's lower") # if your number is higher than you have to find a number thats lower
            
def leave(): #leaves the function and is similar to an retry function
    
    RetryQ = input("Would you like to go again? y,Y or n,N =>") #Variable that gives me Y or N.
    
    if RetryQ == "Y" or RetryQ == "y":   # if the response is y or Y 
        
        main() #restarts program or reruns it
    elif RetryQ == "N" or RetryQ == "n": # if the response is n or N
        
 
        system("clear screen") # clears the screen
        print("You have won the game {} times".format(WinCount)) #prints how much time you win 
        print("see you next time!") #prints see you next time!
        
    else: 
        leave() # if answer is not y or n then you rerun the function
        
main() #reruns the entire code
press enter to start game
attempt 1
Enter a number =>700
you have to find a number that's lower
attempt 2
Enter a number =>500
you have to find a number that's lower
attempt 3
Enter a number =>250
you have to find a number that's lower
attempt 4
Enter a number =>175
you have to find a number that's lower
attempt 5
Enter a number =>125
you have to find a number that's lower
attempt 6
Enter a number =>100
you have to find a number that's lower
attempt 7
Enter a number =>50
you have find a number thats higher
attempt 8
Enter a number =>75
you have find a number thats higher
attempt 9
Enter a number =>104
you have to find a number that's lower
attempt 10
Enter a number =>82
Sorry the number is actually 90
Would you like to go again? y,Y or n,N =>y
press enter to start game
attempt 1
Enter a number =>500
you have to find a number that's lower
attempt 2
Enter a number =>250
you have find a number thats higher
attempt 3
Enter a number =>375
you have to find a number that's lower
attempt 4
Enter a number =>315
you have find a number thats higher
attempt 5
Enter a number =>345
you have to find a number that's lower
attempt 6
Enter a number =>330
you have find a number thats higher
attempt 7
Enter a number =>337
you have to find a number that's lower
attempt 8
Enter a number =>333
you have found the corect answer