Thursday, June 21, 2012

Worksheet [List]

# Lucky Number

name = raw_input("Enter your full name")

def calculateLuckyNumber(name):
    nameSplit = name.split(' ')
    F = len(nameSplit[0])
    S = len(nameSplit[1])
    T = len(nameSplit[2])
    luckyNum = ((2 * F + S) + T) % 10
    return luckyNum

print calculateLuckyNumber(name)

# Using List

sentence = "Dell profit surges on revived business spend"
words = sentence.split()

print words[0] + " " + words[4] + " " + words[5]
print len(words[0]) + len(words[4]) + len(words[5])

#Filtering Words

sentence = 'cat dog lion tiger mouse cow'
sentenceSplit = sentence.split(' ')

for a in range(0,6,1):
    count = len(sentenceSplit[a])
    if count == 3:
        print sentenceSplit[a]

# Sum Up Numbers

num_list = range(0,30,4)
total = 0
for a in num_list:
    total = total + a
print total

# Sum Up Even Numbers

num_list = range(0,30,3)
total = 0
for x in num_list:
    if x % 2 == 0:
        total+=x
print total

# Count even numbers
num_list = range(0,30,3)

even = 0
for x in num_list:
    if x % 2 == 0:
        even+=1
print even

Thursday, 21th June 2012

Today do programming

I know how to do, but don't know how to explain lol
Need make a program called Fortune Teller / Lucky Lucky
Take in the user's name and day, calculate lucky number & color