Friday, July 20, 2012

Thursday, 19th July 2012

Forgot to blog this yesterday was too tired

Guess my body too weak to chiong maple liao x.x

The programming was kinda easy for me, I also edited my code to quite a large extent because adding of improvements.

Edited code of Guessing Game :

from random import randint

ans = randint(1,99)
low = 1
high = 99
guess = ' '
tries = 0

while (guess != ans):
    if (guess) == '0':
        exit()

    guess = raw_input("Guess the number between " + `low` + " and " + `high` + ": (Enter 0 to exit game)")
    tries += 1

    guess = guess.lower()
    if (guess) == 'cheats':
        print "Answer is " + `ans`
        guess = raw_input("Guess the number between " + `low` + " and " + `high` + ": (Enter 0 to exit game)")

    try:
        guess = int(guess)
        if guess < 1 or guess > 99:
            print "Please enter between 1 to 99"
            guess = raw_input("Guess the number between " + `low` + " and " + `high` + ": (Enter 0 to exit game)")

    except:
        print "Please enter between 1 to 99"
        guess = raw_input("Guess the number between " + `low` + " and " + `high` + ": (Enter 0 to exit game)")

    if guess > ans:
        if guess < high:
            high = guess

    elif guess < ans:
        if guess > low:
            low = guess

print "Well done!"
print "The answer is "+ `ans` + "!"
print "You took " + `tries` + " tries"

if tries <= 5:
    print "Wow, you're really lucky!"
elif tries > 5 and tries <= 10:
    print "Not bad, quite lucky~"
else:
    print "Nice effort, you might be luckier on next game!"

No comments:

Post a Comment