Blackpool LUG Python Workshop Part 2

This week Jon led another Python workshop, and Mike, James and Les were there to learn more.

Python Tutorial Lesson 2

We created a loop that allowed players to have multiple chances at guessing the correct number.

Python Tutorial Lesson 2

If you’re guess was too high it said

Python Tutorial Lesson 2

If your guess is too low

Python Tutorial Lesson 2

And if you got it right
Python Tutorial Lesson 2
Jon’s workshop was a great introduction to programming, and you can clearly see how easy it was for us to make our little game by looking at our code below.

# Generate a random number

import random
import easygui as eg

secret = random.randint(1, 50)
guess = 0
tries = 1
eg.msgbox (secret)

# Ask for your guess
while guess != secret and tries < 4: guess = eg.enterbox("What is your guess? ") guess = int(guess) # Compare your guess against the number if guess secret:
eg.msgbox ("You're guess is too high")
elif guess == secret:
eg.msgbox ("You're answer is correct, well done!")

tries += 1
print tries

# Tell you if your guess was correct

print "The answer was : ", secret
eg.msgbox ( "The answer was: " + str(secret))

# Loop if less than six guesses

Massive thanks to Jon for leading these sessions, it has been a great experience.
Also, thanks to Mike for his sterling work on the donated LED wallboards
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s