Friday, June 22, 2012

Last Question in Programming UT 1


def my7(a,b):

    total = a+b

    if (a > b):
        diff = a - b
    else:
        diff = b - a

    if (a == 7 or b == 7):
        return True
    elif (total == 7 or diff == 7):
        return True
    else:
        return False

Friday, 22th June 2012

Today Communication Practice
Need go down for a talk, by Mr Sam Tan

Discussed about how communication barrier can be formed by 4 type of noises
- Physical
- Psychological
- Physiological
- Semantic

Afterwards, went for programming UT
So hard sia lol

Guessing Game

Made this game with the help of 6P and prior knowledge from ITE de C# programming

Just a simple guessing game in Python that only requires user to guess a digit from 1 to 99 by just entering the answer they feel is right

The code :

import random

ans = random.randint(1,99)
low = 1
high = 99
temp_low = 0
temp_high = 0
guess = ' '
tries = 1

while (guess != ans):
    tries = tries + 1
    guess = raw_input("Guess the number between 1 and 99: ")

    try:
        guess = int(guess)
        if guess < 1 or guess > 99:
            print "Please enter between 1 to 99"
            exit()

    except:
        print "Invalid Entry, Game Over"
        exit()

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

        low = guess

        if low > temp_low:
            low = low

        else:
            low = temp_low
        print "You entered " + `guess`
        print "It is HIGHER than " + `low` + " but LOWER than " + `high`

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

        high = guess

        if high < temp_high:
            high = high

        else:
            high = temp_high
        print "You entered " + `guess`
        print "It is HIGHER than " + `low` + " but LOWER than " + `high`

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

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


Gonna try create Scissor, Paper, Stone game with a similar concept when free