nobody's blog


the second best time to plant a tree


Michael Riegert31 Aug 2020

michael+blog@eowyn.net- views


It was on a car ride home from school in 5th grade that I asked my Dad what programming language I should learn, due mostly in part to jealousy about a kid my age who had gotten their own app into the iOS app store. I wanted to emulate their success. My Dad recommended Python, and later that week he bought me Beginning Game Development with Python and Pygame.

From that book I read for hours, copying code into my hand-me-down Lenovo laptop running Kubuntu 10.04, bending the charging cable in weird ways to keep it connected to power, finding the routine of running and debugging back and forth between bash and nano, trying to figure out how everything worked. This is the best program I wrote from that time, the first real program I’ve ever written, and it blew my mind. I loved how I could use the computer to do things, useful things, cool things, the only limit being my imagination. Looking back, this program is really bad for many reasons, but it isn’t really important how bad it is; the most important thing is that I tried.

In middle and high school I had continued to work on it, realizing my mistakes and writing better code, learning more about how programming works. I used what little knowledge I had in future classes and projects as well, not just knowledge about Python, but also knowledge about experimenting and not being afraid to mess around with the code to see how it works, not being afraid of failure. That wouldn’t have been possible had I not written the original. Even though this program has no practical use, or any use to me anymore, this is the tree that was planted 10 years ago that provides me shade now - a foundation for the idea and love of programming and computers - and I’m not sure where I’d be without it. Thank you Dad.


import time
import random

print("Hello")
print("This is The Number Guessing Game")
time.sleep(1)

name = input("What is your name?: ")
time.sleep(1)
diff = input("What difficulty? 1, 2, or 3: ")

playing = bool(True)
f = [1]
g = [1]
win = bool(False)


print('______________________________________')
time.sleep(1)
print(' ')

if diff == "1":
    chance = random.randint(10, 13)
elif diff == "2":
    chance = random.randint(6, 9)
elif diff == "3":
    chance = random.randint(3, 5)
elif diff == "quit":
    exit()
    quit()
else:
    print("Restart and choose 1, 2 or 3 only.")
    input()
    exit()
    quit()


high = ["High Scores:"]
print('I shall choose a number from 1 - 99, and you have to guess the number.')
time.sleep(1)
print('If you do, you win!')
time.sleep(1)
print('You have ' + str(chance), 'guesses')
time.sleep(1)

while playing == bool(True):
    number = random.randint(10, 99)
    number2 = random.randint(10, 99)

    print('______________________________________')

    def guesstime(number):
        guess = input("Guess: ")
        global win
        global score
        if guess == str(number):
            print("You win!")
            time.sleep(2)
            if number == number2:
                print('Double score for double number!')
                score = (((chance - len(g))*int(diff)+1)*40)

            else:
                score = (((chance - len(g))*int(diff)+1)*20)

            list.append(g, 1)
            list.append(g, 1)
            win = bool(True)
        elif guess == 'minecraft':
            print(int(number) + int(15))
            print('______________________________________')
            g.remove(1)
        elif guess != str(number) and len(g) == chance:
            print("Sorry, you lost")
            score = (((chance - len(g))*int(diff)+1)*20)
        elif guess == 'quit' or guess == 'end':
            quit()
            exit()

        else:
            if guess >= str(number):
                print(' ')
                print("Hint: The number is less than your guess")
            elif guess <= str(number):
                print(' ')
                print("Hint: The number is more than your guess")
            else:
                print('No hint')
            time.sleep(1)
            print(" ")
            print("You've guessed " + str(len(g)), "times")
            print('You have ' + str((chance - len(g))), 'guesses left')
            time.sleep(1)   
            print('______________________________________')




    while len(g) <= int(chance) and win == bool(False):
        guesstime(number)    
        list.append(g, 1)
    print('______________________________________')

    print('Your score is ' + str(score))
    print('You guessed ' + str(len(g) - len(f)), 'times')
    print('The number was ' + str(number))

    g = [1]
    win = bool(False)
    high.append(score)

    print('______________________________________')
    time.sleep(1)
    print('Do you want to play again?')
    play = input('yes or no: ')
    if play == 'yes' or play == '':
        playing = bool(True)
        print('======================================')
        print('NEW ROUND')
        print('New number')
        print('You have ' + str(chance), 'guesses')
#    elif play == 'minecraft':
#        playing == bool(True)
#        print('======================================')
#        print('NEW ROUND')
#        print('MINECRAFT FTW')
#        chance = 64
#        print('you have ' + str(chance), 'guesses')
    else:
        playing = bool(False)
        print('Your high scores are ' + str(high))
        print('END. THANK YOU FOR PLAYING')
        fileObj = open('High_Scores_'+ name +'.txt','w')
        fileObj.write(str(high))
        fileObj.write(', ')
        fileObj.write(str(name))
        fileObj.write(', ')
        fileObj.write('Difficulty: ' + str(diff))
        fileObj.close()
        input()

P.S.: It still works! - though you have to wrap all user input in quotations.



© 2021 Michael Riegert
Unless otherwise noted, content is under a CC BY 4.0 license.