Posted by: kezhong | November 19, 2008

My first Python Program

I’ve never used Python before. This is my first Python program.  I feel Python like Java language, but more like natural language.

#!/usr/bin/python

import random

num_guess = random.randrange(1,100)

print “Instruction: ”
print “The game is about to guess number between 1 to 100.”
print “The less times you guess, the more you get score. ”

guess_time=0
while (True):
try:
guess=int(raw_input(“Enter a number:”))
guess_time+=1
if guess_time > 10:
print “Is it difficult?”
break
if guess > num_guess:
print “Too high!”
elif guess < num_guess:
print “Too low!”
else:
print “Correct!”
break
except:
print “You input non-number! Try again!”
print “You guess”,guess_time,”times”
if guess_time > 7:
print “You should work hard!”
elif guess_time > 5:
print “Good job!”
elif guess_time > 3:
print “Excellent!”
else:
print “Unbelievable!”


Responses

  1. Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru


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

Categories

%d bloggers like this: