# For Loop
for a in range(1,10,2):
print `a` + ": hello"
# For Loop / List
from random import randint
randomList = []
for x in range(10):
randomList.append(randint(1,100))
if randomList[x] % 2 != 0:
print randomList[x]
print randomList
# List / Sum
def totalUp():
listOfNum = [4,3,6,2]
total = sum(listOfNum)
return total
print totalUp()
# Functions
def areaOfRect(w,h):
area = w * h
return area
print areaOfRect(5,10)
# Function / List
def printList(x):
a = x[0]
b = x[-1]
c = "First element is " + `a` + ", while Last element is " + `b`
return c
print printList([154, 198, 123, 136, 239, 257, 207, 262, 178, 228])
# Function / List II
def sumList(x):
a = x[0]
b = x[-1]
c = "The sum of " + `a` + " and " + `b` + " is " + `(a + b)`
return c
print sumList([193, 220, 113, 248, 132, 289, 188, 124, 163, 255])
# List / Maximum
def findMax(x):
maxNum = x[0]
for a in range(len(x)):
if x[a] > maxNum:
maxNum = x[a]
return maxNum
print findMax([171, 135, 160, 295, 105, 253, 169, 224, 298, 139])
# List / Maximum by 4
def findMaxBy4(x):
maxNum = x[0]
for a in range(len(x)):
if x[a] % 4 == 0:
if x[a] > maxNum :
maxNum = x[a]
return maxNum
print findMaxBy4([233, 135, 109, 117, 300, 268, 185, 259, 298, 171])
# List / Maximum / Minimum
def diff(x):
maxNum = x[0]
for a in range(len(x)):
if x[a] > maxNum:
maxNum = x[a]
minNum = x[0]
for a in range(len(x)):
if x[a] < minNum:
minNum = x[a]
difference = maxNum - minNum
return `maxNum` + " - " + `minNum` + " = " + `difference`
print diff([110, 116, 209, 163, 287, 222, 293, 268, 275, 213])
Thursday, June 28, 2012
Reflection Journal for Programming Week 08
The code should be continuous...
1) Create a list named 'numList' with the following numbers: 4, 7, 9, 0, 9, 7, 43, 2, 6, 87
2) Print out the last element in 'numList'
3) Write a loop that prints out ALL the elements in numList (first number printed must be 4)
4) Write a loop that prints out ALL the elements in numList in REVERSE ORDER (first number printed must be 87)
5) Write a loop that prints out all the numbers in numList that are GREATER THAN 10
The code :
numList = [4, 7, 9, 0, 9, 7, 43, 2, 6, 87]
print "This is last element " + `numList[-1]`
print ' '
for x in range(len(numList)):
print numList[x]
print ' '
numList.reverse()
for x in range(len(numList)):
print numList[x]
print ' '
for x in range(len(numList)):
if numList[x] > 10:
print "Greater than 10 got " + `numList[x]`
1) Create a list named 'numList' with the following numbers: 4, 7, 9, 0, 9, 7, 43, 2, 6, 87
2) Print out the last element in 'numList'
3) Write a loop that prints out ALL the elements in numList (first number printed must be 4)
4) Write a loop that prints out ALL the elements in numList in REVERSE ORDER (first number printed must be 87)
5) Write a loop that prints out all the numbers in numList that are GREATER THAN 10
The code :
numList = [4, 7, 9, 0, 9, 7, 43, 2, 6, 87]
print "This is last element " + `numList[-1]`
print ' '
for x in range(len(numList)):
print numList[x]
print ' '
numList.reverse()
for x in range(len(numList)):
print numList[x]
print ' '
for x in range(len(numList)):
if numList[x] > 10:
print "Greater than 10 got " + `numList[x]`
Archery Score
[Original]
from random import randint
def getScore():
rdmScore = []
for a in range(10):
rdmScore.append(randint(100,300))
return rdmScore
rdmScore = getScore()
def lowestScore():
lowest = min(rdmScore)
return lowest
def highestScore():
highest = max(rdmScore)
return highest
def averageScore():
total = sum(rdmScore)
avg = float(total)/float(len(rdmScore))
return avg
print "Score (10 games): " + `rdmScore`
print "Average Score : " + `averageScore()`
print "Lowest Score : " + `lowestScore()`
print "Highest Score : " + `highestScore()`
[With Bonus]
from random import randint
def getScore():
rdmScore = []
for a in range(10):
rdmScore.append(randint(100,300))
return rdmScore
scoreList = getScore()
def lowestScore(scoreList):
lowest = min(scoreList)
return lowest
def highestScore(scoreList):
highest = max(scoreList)
return highest
def averageScore(scoreList):
total = sum(scoreList)
avg = float(total)/float(len(scoreList))
return avg
players = []
for i in range(5):
players.append(getScore())
for i in range(len(players)):
print "Player: " + `i+1`
print "Score (10 games): " + `players[i]`
print "Average Score : " + `averageScore(players[i])`
print "Highest Score : " + `highestScore(players[i])`
print "Lowest Score : " + `lowestScore(players[i])`
worst = 0
worstScore = averageScore(players[0])
for i in range(1,len(players)):
if averageScore(players[i]) < worstScore:
worst = i
worstScore = averageScore(players[i])
print "Worst player is : Player " + `worst+1`
print "His average score is " + `worstScore`
best = 0
bestScore = averageScore(players[0])
for i in range(1,len(players)):
if averageScore(players[i]) > bestScore:
best = i
bestScore = averageScore(players[i])
print "Best player is : Player " + `best+1`
print "His average score is " + `bestScore`
Thursday, 28th June 2012
Ate maggie mee with 2 eggs at 2+ am, too hungry after do programming lol
Brain encountered some logic errors, not sure how to solve
Think I too tired today also x.x
Managed to solve today's problem statement de bonus part by myself
After a long time though
I find it really stupid if someone wants me to approach the person and understand the person from just facial expressions, how the hell do I know
Brain encountered some logic errors, not sure how to solve
Think I too tired today also x.x
Managed to solve today's problem statement de bonus part by myself
After a long time though
I find it really stupid if someone wants me to approach the person and understand the person from just facial expressions, how the hell do I know
Wednesday, June 27, 2012
Display Month Function
month = raw_input("Enter the number of month")
try:
month = int(month) - 1
if month < 0 or month >= 12:
print "Please enter between 1 to 12"
exit()
except:
print "Error"
exit()
def displayMonth(month):
listOfMonth = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return listOfMonth[month]
print displayMonth(month)
Purpose of this code:
- Calculate the number of month and display the month's name
* Plans to take in day & year of birthday
* To calculate horoscope and chinese zodiac
try:
month = int(month) - 1
if month < 0 or month >= 12:
print "Please enter between 1 to 12"
exit()
except:
print "Error"
exit()
def displayMonth(month):
listOfMonth = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
return listOfMonth[month]
print displayMonth(month)
Purpose of this code:
- Calculate the number of month and display the month's name
* Plans to take in day & year of birthday
* To calculate horoscope and chinese zodiac
Wednesday, 27th June 2012
Today finally no wear full black
Instead, red top and white bottom
Think this pattern would be more suitable for Creative Concepts
Today's problem trigger is Belief
My team chose Plastic Surgery, is it okay?
I found a few pictures that has plastic surgery jokes in them
Arguments....
Seriously?
Instead, red top and white bottom
Think this pattern would be more suitable for Creative Concepts
Today's problem trigger is Belief
My team chose Plastic Surgery, is it okay?
I found a few pictures that has plastic surgery jokes in them
Arguments....
Seriously?
Tuesday, June 26, 2012
Tuesday, 26th June 2012
Today need learn molecular stuffs in science, don't think I know how to do this 1 lol
One good thing, group with Muffin =D
So troublesome to live and act normally
I think I will just be emo
One good thing, group with Muffin =D
So troublesome to live and act normally
I think I will just be emo
Monday, June 25, 2012
Monday, 25th June 2012
Today have to watch Matrix for Art of Story
I watched all three movies before -_-
Simply watched Dantalian no Shoka during the movie lol
Only help little in today's presentation
Changed powerpoint background to black and font to green for a Matrix feel
Went to Causeway Point's Pastamania for dinner with Muffin
She ordered Turkey Bacon Cheesy Crumble while I ordered Hawaiian Pizza
Everytime I say I eat Hawaiian Pizza at Pastamania, people will doubt me
Thought I referring to Pizza Hut -_-
Bought 5 boxes of tissue just now
Price tag wrote $4.00 but $2.99 when bring to counter
$3.00 for 5 boxes of tissue is cheap
I watched all three movies before -_-
Simply watched Dantalian no Shoka during the movie lol
Only help little in today's presentation
Changed powerpoint background to black and font to green for a Matrix feel
Went to Causeway Point's Pastamania for dinner with Muffin
She ordered Turkey Bacon Cheesy Crumble while I ordered Hawaiian Pizza
Everytime I say I eat Hawaiian Pizza at Pastamania, people will doubt me
Thought I referring to Pizza Hut -_-
Bought 5 boxes of tissue just now
Price tag wrote $4.00 but $2.99 when bring to counter
$3.00 for 5 boxes of tissue is cheap
Subscribe to:
Posts (Atom)




