My teacher has set us this work and I will be locked in the basement if I can't do it


• Computer generates random number
• Ask for guess
• Compare the answers
• Tell the user if they’re wrong or right
• If right say well done
• If it’s wrong tell them to go higher or lower
• If the guess is higher, say “lower”
• If the guess is lower, say “higher”


print("Welcome to guess the number!")

name = input("\nWhat is your name?")
print("\nHello", name,"!")

from random import *

count = 0
guess = 0

number = randint(1,100)

while guess != number:
guess = int(input("What is thou's guess?"))
if guess > number:

    count += 1

elif guess < number:

    count += 1

    print("Well done,", name,"! You made", count," attemmpts to find the number!")


Try this here

from random import randint

def check_answer(answer):
    """ This method makes sure the user enter a number and nothing else
        if the user enter anything other than a number then it will prompt
        for the right input
            answer = int(answer)
        except ValueError:
            print("answer must be a number!!!")
            answer = input("What is that number?\n>>>")
    return answer

exit = False
runs,correct_guesses  = 0,0
record = dict()

print("|         RANDOM GUESSING GAME         |")
print("|   push a negative integer to exit    |")

while(exit != True):

    # define the range of the computers random guess
    computer_guess = randint(0, 50)
    print("The computer has guessed a number")
    answer = input("What is that number?\n>>>")

    answer = check_answer(answer)
    attempts = 1

    # sentinel to exit
    if(answer < 0):
        exit = True
        while(answer != computer_guess):
            if(answer < computer_guess):
                print("Wrong. Make a higher guess")
            if(answer > computer_guess):
                print("Wrong. Make a lower guess")
            answer = check_answer(input("What is that number?\n>>>"))

            #sentinel to exit
            if(answer < 0):
                exit = True
            print("Well done")

    #store the results of the quiz in a dictionary
    record["run "+str(runs)] = [attempts, computer_guess]
print("|          Session Terminated          |")
print("Guesses made by computer ", runs)
print("Correct guesses", correct_guesses)
print("record of attempts below\n")
for i in sorted(record):
    print("%s you made %s attempts to get the answer %s"%(i, record[i][0],record[i][1]))

if you get an error on the user input just change the input(python 3) to raw_input(python 3).
You can modify the code and add as much aesthetics as you want


Try this!

def why_my_homework_is_not_done(reason):
    if reason == "procrastination":
        print "Maybe I deserve to be locked in the basement so I can reflect on how to make better use of my time" 
    elif reason == "I don't understand it": 
        print "Maybe I should ask for assistance instead of asking for someone to do it for me."
        print "Maybe I should take advantage of being locked in the basement to open my textbook and study a little bit more."
        print "Maybe I should ask a peer to come home so we can code side by side and help each other out while being locked in the basement together."
        print "Maybe I should stop trying to find excuses and give my homework one more shot."

Worked for me! Sure it will work for you too! :wink:


Why would you be locked in the basement what?!?!



Don't worry, I doubt he will be really locked into a basement... :grinning:

I believe he said that to stress how important the assignment was and that he badly needed help with it very quickly... :wink:

...Well... At least I hope he was not locked into a basement... But that would explain why he never replied to any of the help we provided him...! ahah just kidding


Phew, I'm out I managed to dig a tunnel out of there. Thanks for the help I passed and am now working for ISBN! @denisaltroy @rydan