Python Code – Guessing Game
Recovered Blog Post from Sept 5, 2015
The asset of creating.
I want to pass it on.
I want to pass it forward.
To create something from nothing.
Lately I’ve been trying to get my cousins to learn how to program. They’re in their late teens and deciding where they want to take their lives. Regardless of where they go and what field they end up studying, having the ability to create tools as you need them is an indispensable asset.
Games are really fun, and I think it’s a great place to start challenging oneself.
I’ve started with a number guessing game where the computer picks a number between 1 and 10 and the player has to guess what it is.
They haven’t learned functions yet, but they’re beginning to learn how to apply if-then logic and flow data in and out of loops.
You can find the code below.
Next on the agenda is “Rock, Paper, Scissors!”
guess = 0count = 0secret = random.randint(1,10)
while( guess != secret):print ‘Select a number between 1 and 10: ‘guess = raw_input()count += 1
if (int(guess) == secret):print ‘correct’break;else:
print ‘the correct answer is: ‘ + str(secret) + ‘\n you selected: ‘ + str(guess)# print ‘You (incorrectly) guessed ‘ + str(guess) + ‘ please try again’ print ‘only took you ‘ + str(count) + ‘ guesses’