I am teaching a python class to some high school seniors. I was thinking of doing an oracle game where the computer would come up with a number, and the player would guess it. These are brand new coders, and I'll teach them what they need to know to get there, but is this a good first project? I have my code here as my implementation of this game. I want to make sure that I don't teach them anything bad or give them bad habits.My software requirements are:Must generate a random (or psuedo-random) numberMust import a libraryMust use a loopMust take user inputMust tell the user to guess higher or lower# importsimport randomimport timeimport sysimport os# set global variablesMIN_NUMBER = 1MAX_NUMBER = 10# important functionsdef get_random(min, max):     print Coming up with a number.    time.sleep(2)    random_number = random.randint(min, max)    print Got it!    return random_numberdef to_int(x):    try:        x = int(x)        return x    except ValueError:        print That is not a whole number.        return Falsedef how_close(guess, right_answer):    return right_answer - guessdef hi_low_done(delta):    if delta < 0:        print Guess lower.        return False    elif delta > 0:        print Guess higher.        return False    else:        print You got it!        return True# main Program#clear screenos.system('cls')  # on windowsprint Welcome. I am the Oracle.print I will think of a number between %s and %s. Guess it and you will win! % (MIN_NUMBER, MAX_NUMBER)while True:    user_answer = raw_input(Ready? <y/n> )    if user_answer.lower() == 'y' or user_answer.lower() == 'yes':        print Great! Let's go.        break;    elif user_answer.lower() == 'n' or user_answer.lower() == 'no':        print Okay. Consult the Oracle when you are ready.        sys.exit()oracles_number = get_random(MIN_NUMBER, MAX_NUMBER)number_of_guesses = 0while True:     number_of_guesses = number_of_guesses + 1    user_answer = raw_input(\nGuess> )    user_answer = to_int(user_answer)    # if user answer is outside min max... else...    if user_answer:        delta = how_close(user_answer, oracles_number)        done = hi_low_done(delta)        if done:             break;print It took you %s guesses to guess my number. % (number_of_guesses)I guess my concerns with my code are:Is this simple enough? It isn't the first thing they will code, but the first project they will do. (maybe group project?)Did I make any blatant errors or In python, you should do this instead errors? Python isn't my first language so I'm not sure.I have created a gist file with my most up-to-date version of this.
Number guessing game for beginners
python;python 2.7;number guessing game
In my opinion I think this is a very very simple problem and much less for high school seniors. Also the amount of code in your project is too much. This will thwart away students and is not pythonic. My aim for the first time students should be to show them how beautiful coding can be and the sheer amount of power you can get with few lines of code. Below is how I will implement it. 1st Solution: Without loop. Uses recursion, use of global etc. import randomdef check():    global count  # good example of use of global    guess = int(raw_input(Take a guess\n))    if guess == no:        print Good job, %s! You guessed my number in %d guesses! %(name,count)    if guess < no:        print Your guess is too low.        count +=1                check()              if guess > no:        print Your guess is too high        count +=1        check()name = raw_input(Hello! What is your name?\n)print Well,  + name + , I am thinking of a number between 1 and 20no = random.randint(1,20)global countcount  =1check()2nd Solution: With loops. Less code. Showcases importance of while loops. Satisfies all five of your software requirements.import randomname = raw_input(Hello! What is your name?\n)print Well,  + name + , I am thinking of a number between 1 and 20no = random.randint(1,20)guess = int(raw_input(Take a guess\n))count =1while guess != no:        if guess < no:        print Your guess is too low.                     if guess > no:        print Your guess is too high    count +=1    guess = int(raw_input(Take a guess\n))print Good job, %s! You guessed my number in %d guesses! % (name ,count)Best would be you should showcase both the approach so that they can understand the difference, appreciate while loops, get a liking for python. Avoid using too much constructs (checking for their input, errors) etc. Testing, using OOPs, error handling etc. should be kept for further stages. 