Tag Archives: Python

Python Code – Guessing Game

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!”

Toodles,

#!/usr/bin/python
import random

guess = 0
count = 0
secret = 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’

 

Raspberry Pi 2 Model B and Ostriches

I recently came across a micro computer with a nifty name and decided to invest in it. I thought I was the coolest guy in town and started gloating about it. I even tried joking around with my dad.

“Hey, dad guess what I bought… a ‘Raspberry Pi’!!!”.
I snickered away, thinking he’d assume it’s a delicious pie.

He responded with “Oh that’s neat, I think I saw someone fly one and run face recognition software on it at a big data conference a few years ago.”

I felt like a total ostrich having my head in the ground for months. How could have I not come across something so amazing.

It’s called the Raspberry Pi 2 Model B and apparently has been out in the market for years. Everyone I turned to had seemed to not only have heard of it but also heard of awesome projects made with them.

I ended up buying it because I wanted to do some mad scientist projects using the voice recognition open source project called Jasper.

Currently, I’m using my Pi Right now I’m using it to sharped my networking skills and teach my cousins how to program. So far we’ve made a number guessing game on the python. I want them to learn how to make a rock paper scissors game and some more fun and simple games.

It’s really exciting making something from nothing. It’s quite powerful for something that runs near 50 bucks. Definitely a something to invest in if you want to try out some projects or gain a new skill.

Here’s some hardware specs on it:

  • 900MHz Quad Core CPU
  • 1GB Ram
  • 4 USB Ports
  • 40 GPIO Pins
  • HDMI Port
  • Ethernet Port
  • audio jack
  • Camera Interface
  • Display Interface
  • Micro SD card slot