Python Guessing game - incomplete code
Question: Can someone please help me re-design this code so that the program prompts the
user to choose Easy, Medium or Hard.

    
    
    Easy: maxNumber = 10
    Medium: maxNumber = 50
    Hard: maxNumber = 100
    

It should choose a random number between 0 and the maxNumber. The program will
loop calling a function the get the users guess, and another to check their
guess. a function named “getGuess” which will ask the user for their guess and
reprompt if the guess is not between 0 and the maxNumber r function named
“checkGuess” which will check the users guess compared to the answer. The
function will return “higher” if the number is higher than the guess; “lower”
if the number is lower than the guess and “correct” if thenumber is equal to
the guess. Once the user has guessed the number correctly the program will
display all their guesses and how many guesses it took them. Then the program
will ask the user if they would like to try again and redisplay the difficulty
menu.

    
    
    import random
    
    guessesTaken = 0
    
    print('Hello! Welcome to the guessing game')
    myName = input()
    
    number = random.randint(1, 20)
    print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
    
    while guessesTaken < 6:
        print('Take a guess.') 
        guess = input()
        guess = int(guess)
    
        guessesTaken = guessesTaken + 1
    
        if guess < number:
            print('Your guess is too low.') 
    
        if guess > number:
            print('Your guess is too high.')
    
        if guess == number:
            break
    
    if guess == number:
        guessesTaken = str(guessesTaken)
        print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
    
    if guess != number:
        number = str(number)
        print('Nope. The number I was thinking of was ' + number)
    


Answer: You could do something like this:

    
    
    from random import randint
    myName = input("what's your name? ")
    def pre_game():
        difficulty = input("Choose difficulty: type easy medium or hard: ")
        main_loop(difficulty)
    
    def main_loop(difficulty):
        if difficulty == "easy":
            answer = randint(0, 10)
        elif difficulty == "medium":
            answer = randint(0, 50)
        else:
            answer = randint(0, 100)
        times_guessed = 0
        guess = int()
        while times_guessed < 6:
            print('Take a guess.')
            guess = input()
            guess = int(guess)
    
            times_guessed += 1
            if guess < answer:
                print('Your guess is too low.')
    
            if guess > answer:
                print('Your guess is too high.')
    
            if guess == answer:
                break
    
    
        if guess == answer:
            guessesTaken = str(times_guessed)
            print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
    
        if guess != answer:
            print('Nope. The number I was thinking of was ' + str(answer))
        next = input("Play again? y/n: ")
        if next == "y":
            pre_game()
        else:
            print("Thanks for playing!")
    pre_game()
    

