Monday 23 September 2013

working with file

#creating range

for item in range(0,100,5):
    print item
   
#working with file in python

crip=open('flash.txt','w')
crip.write('sing the melody')
crip.close()
#print crip

#reading a file
x=open('flash.txt','r')
y=x.read()
x.close()
print (y)

#creating my own file
good_day=open('rise.txt','w')
good_day.write('I enjoy my sunday very well with my sister on her birthday')
good_day.close()
#print good_day

happy=open('rise.txt','r')
well=happy.read()
happy.close()
print (well)

#appending a file
good_day=open('rise.txt','a')
good_day.write('The both of us went for service at my church')
good_day.close()
print good_day

happy=open('rise.txt','r')
well=happy.read()
happy.close()
print(well)




Friday 20 September 2013

Learning Python-
Intermediate
Lesson 4 :Iteration and Tuples
Carter Draper
Sources: Zane Cochran, Allan Martell & Code AcademyLet’s get ready!
 List Review
 Using Functions With Lists
 Using the Entire List in a Function
 For Loop
 While Loop
 TuplesFor Loops
For loops are traditionally used
when you have a piece of code
which you want to repeat n number
of times.
Executes a sequence of statements
multiple times and abbreviates the
code that manages the loop
variable.
for letter in 'Python': # First Example
print 'Current Letter :', letterrange vs. xrange in for
loops
The range function creates a list
containing numbers defined by
the input
The xrange function creates a
number generator
The range function generates a
list of numbers all at once, where
as xrange generates them as
needed
for a in range(10):
print (a)
for x in xrange(5):
print xAssignment
Lesson 4
For Loops
ExercisesWhile Loops
A while loop statement in Python
programming language repeatedly
executes a target statement as long as
a given condition is true.
It tests the condition before executing
the loop body.
count = 0
while (count < 9):
print 'The count is:', count
count = count + 1Assignment
Lesson 4
While Loops
ExercisesTuples
A tuple is a sequence of
immutable Python objects. Tuples
are sequences, just like lists.
The only difference is that tuples
can't be changed i.e., tuples are
immutable and tuples use
parentheses and lists use square
brackets.
tup1 = ('physics', 'chemistry', 1997, 2000);Accessing Values in Tuples:
To access values in tuple, use the
square brackets for slicing along with
the index or indices to obtain value
available at that indexAssignment
Lesson 4
While Loops
ExercisesReflection
Learning Python-
Intermediate
Lesson 3 : Lists & Functions
Carter Draper
Sources: Zane Cochran, Allan Martell & Code AcademyLet’s get ready!
 List Review
 Function Review
 Using Functions With Lists
 Using the Entire List in a Function
 Lists of ListsList Review
 Indexing an element in a list
 x[n]
 Modifying an element in a list
 x[n] = v
 Appending an element to a list
 x.append(item)List Review
3 Ways to Remove Elements from
Lists
 Remove
 n.remove(item) will remove the actual item if it
finds it.
 Del
 del(n[1] is like .pop in that it will remove the item
at the given index, but it won't return it.
 Pop
 n.pop(index) will remove the item at index from
the list and return it to you.Assignment
Lesson 3
List Review
Exercise 0-3Function Review
 Function Syntax
def test(z):
return z + 1
print test(5)
⇒ Declare Function
⇒ Return Value
⇒ Call Function
 Unknown Number of Arguments
def test2(*args):
print args[0]
⇒ gets all arguments
⇒ prints first argumentAssignment
Lesson 3
Function Review
Exercise 0-2Using Functions With Lists
 You can pass lists to
functions just like any
other argument.
 You can modify elements
in a list while in a function.
 You can also add and
remove elements onto a
list inside a function
 Functions can return single
elements from the list or
the entire list.
my_list= [ 8, 2, 1, 9 ]
def test1(a_list):
return a_list [1]
test1(my_list)
def test2(a_list):
a_list[1] += 1
return a_list
test2(my_list)Assignment
Lesson 3
List Functions
Exercise 0-2Using the Entire List in a
Function
 We’ve changed or added
or removed ONE element
in a list.
 How could we change
multiple elements or all
the elements?
 We can use a for loop and
the range function.Using the Entire List in a
Function
 range( )
 A shortcut for
generating a list
 Can take 3 different
arguments
depending on what
you want it to do
1 Argument
Starts at 0
Increases by 1 until 1 less than 1st argument
range(2) ⇒ [0, 1]
2 Arguments
Starts at 1st argument
Increases by 1 until 1 less than 2nd argument
range(1,3) ⇒ [1, 2]
3 Arguments
Starts at 1st argument
Increases by 3rd argument until less than
2nd argument
range(2,8,3) ⇒ [2,5]Using the Entire List in a
Function
 range(3)
 range(0)
 range(0, 5)
 range(2, 4)
 range(2, 5, 2)
 range(1, 12, 3)
[0, 1, 2]
[]
[0, 1, 2, 3, 4]
[2, 3]
[2, 4]
[1, 4, 7, 10]Using the Entire List in a
Function
 Let’s pretend we have a
list [3, 5, 7]
 How could we find out the
result of all the items in
the list added together?
 What if we didn’t know
how many items were in
the list?
# The Hard Way
n = [3, 5, 7]
count = n[0] + n[1] + n[2]
print count
# The Easy Way
def total(a_list):
sum = 0
for item in a_list:
sum += item
return sumAssignment
Lesson 3
Entire List
Exercise 0-4Lists of Lists
 We know functions can take two arguments
 What types of things could we do if we gave it
two lists?
 farmA = [“sheep” , “chicken”, “cow”]
 farmB = [“goat”, “horse”, “duck”]
 We could write a function to combine these lists!
 You can combine lists like this: farmA + farmBLists of Lists
 We’ve looked at lists of numbers and lists of
strings
 What about lists of lists?
List of Lists
List 1 , List 2 , List 3
-----------------------------------------------
warehouse = [ [1, 2, 3], [4, 5, 6, 7], [8, 9]
]Assignment
Lesson 3
List Lists
Exercise 0-2Quick Look & Reflection
 Are you becoming more comfortable with using lists
and functions?
 What has been your favorite thing so far?
 When would it make sense to have a list of lists?

working with loop and while loop

#for loop
for letter in 'python':
    print 'current letter:',letter

#creat a list of five colors
colors=['red','blue ','green','yellow','orange']
print colors

for green in 'favorite colors':
   print 'favorite colors:',colors

#range
for a in range(20):
    print(a)

#using xrange
for x in xrange(20):
    print x

#using odd number in xrange
for x in xrange(30):
    if x%2==0:
        continue
print x

#using even number in xrange
for w in xrange(20):
    if w%2!=0:
        continue
    print w

#counting from 500,600
for x in xrange(500,600):
    print x

#working with while loop
count=0  
while(count<9):
    print 'the count is:', count
    count=count+1

#using while loop
add=11
while(add<35):
    print 'this is great then :',add
    add=add+1
#

  
  
  

Wednesday 18 September 2013

Intermediate list function

INTERMEDIATE LIST FUNCTION

#creating list
continent=["asia","europe","africa"]
print continent


#indexing a list
earth=continent[2]
print earth

#modifying a list
continent[2]='australia'
print continent

#appending a list
continent.append('america')
print continent

#deleting using pop
continent.pop(1)
#deleting using remove
continent.remove('america')
print continent

#deleting using del
del(continent[0])
print continent


#function review
girls=3
def caculation(x):
    return x*4
print caculation(girls)

#multiple argument
liberia=['buchanan','greenville','robertsport','kakata','zwedra','monrovia']
print liberia

#placing list into function
def visit(k):
    return k
print visit(liberia)

#printing one item from list in funx
def home(new_list):
    return new_list[2]
print home(liberia)

#deleting in function
def mon(galaxy):
    galaxy.pop(4)
    return galaxy
print mon(liberia)

#adding in funx
def sun(light):
    light.append('gbanga')
    return light
print sun(liberia)

#counting in funx
count=[1,2,3,4,5,6,7,8,9,10]
def join_list(word,number):
    return word+number
print join_list(liberia,count)

#loop list using for in funx
for i in count:
    print i

for k in liberia:
    print k

for i in count:
    print i+1

#adding a new list in funx
streets=[[1,2,3,],[6,8,7,9]]
def shine(m):
    result=sum(m,[])
print shine(streets)


   




Monday 16 September 2013

Assignment

#create a list called continent
continent=['Africa','Antarctica','Asia','Australia','Southamerican','Nouthamerican','Europe']
print continent

#print only the five continent
print continent [5]

#update the continent on the list by adding two planet: 'earth' and 'mars'
continent.append("earth")
print continent

continent.append("Mars")
print continent

#4
continent[3]="pluto"
print continent

#5
print len("continent")

#6
galaxy=continent[0:5]
print galaxy

space=continent[5:9]
print space

#7
continent.insert(4,"mercury")
print continent

#8
for item in continent:
    print continent

#9
continent_africa=['liberia,''guinea','ghana','congo','sierrialeon','zimbobwe','libya','togo','egypt','tunisia','somalia','algerie','benina','mila','niger','kenya','gabon','chad','nigeria']
print continent_africa

for counties in continent_africa:
  print continent_africa
 
#10
space.pop(2)

#part two
liberia={'grandcapemount':'via','bong':'kpelle','grandgedeh':'Kremlin','grandbassa':'bass a','grandkru':'kru','maryland':'gebo','grandgee':'gerbo','sinoe':'sarpo','nimba':'mano'}
print liberia

for counties in liberia:
    print liberia

#2
print Liberia["nimbi"]

#3
Liberia["fellah"]='Norman'
print Liberia

#4
street={}
print street

#5
street['Benson']=1
street['crown hall']=4
street['front']=7
street['waterside']=5
street['colemanhall']=3
print street

#6
del(liberia['maryland'])
print liberia

#7
street['draperline']=[8,3,9,11,2]
print street

#8
street['draperline'].sort()
print street

#9
house_thing={'table':'it is where we put food','pan':'is where we eat','pot':'is where we cook our food','chair':'is where we sit','bed':'is where we sleep'}
print house_thing

#10
print house_thing
  
print liberia

Friday 6 September 2013

working with dictionary

# dictionary
school={'techers':7,'students':20,'janitor':1,'cook':3,'principal':1,'cashier':2}
print school

#updating a dictionary
school["sponsor"]=6
print school

#printing key and values in a dict
print school.keys()

#print value of a key
print school['students']

#deleting an item from diet
del(school['janitor'])
print school
print len(school)

#empty diet
menu={}
menu['wine']=21.50
menu['rice']=12.5
menu['fufu']=13
menu['peza']=24.6
menu['cake']=3.00
menu['frie chicken']=5.00
menu['softdrink']=35.00
menu['cornbread']=45.00
menu['dosa']=16.00
print menu

for item in menu:
    print menu[item]
for key,value in menu.items():
    print key,value

citizens={'liberia':'liberians','Nigeria':'nigerians','Americans':['chinese','europeans','africans','asians']}
print citizens

#using for loops
for key,value in citizens.items():
    print key,value
citizens['Americans'].sort()
print citizens

citizens['brazil']=['brazilians','south american']
print citizens                                                                  
                                                                  
                                                                  
                                                                    

Wednesday 4 September 2013

creating a listing on zoo animals

please to met the different kind of animals

#1
zoo_animals=["elephant","lion","zebra","leopard"," monkey", "donkey"," goat", "cow"," giraffe ","crocodile", "parrot"," came" ,"fox", "bear", "horse"]
print zoo_animals

#2
print zoo_animals[7]

#3
print zoo_animals[0:10]

#4
zoo_animals[10]="snake"
print zoo_animals

#5
zoo_animals.append("ant")
print zoo_animals

#6
zoo_animals.insert(8,"pig")

#7
print Len("zoo_animal")

#8
for animals in zoo_animals:
    print "feed my %s" %animals

#9
zoo_animals.sort()
print zoo_animals

#10
class_mates=["Helena","maria","Ma-hawa","Dyna","Jackson","Leona","Linnia","Fatu","Victoria"]
print class_mates
           

creating a list on zoo

Monday 2 September 2013

working with functons

LIST
food_list=["pepper","crab","vita","coal","chicken","pigfoot","oil"]
print food_list

boy_list=[]
print boy_list

print food_list[4]
#updating
food_list[6]="cassava leaf"
print food_list
#appending a list

food_list.append("onion")
print food_list
#creating a new list
house_list=[1,2,3,4,5]
x=food_list+house_list
print x
food_list.pop(2)
print food_list
print len(x)

#slicing list
z=x[5:]
print z

p=x[1:3]
print p
We are workng with intermediate functins. this is one of the functions, Built_in function. It provided as part of pyhon_raw_input(). type(). float,int().
Function is a reusable section of code written to perform a specific task. some of the key word we use in the function.
1,def

Friday 30 August 2013

Intermediate 30,note

"""
import math
print math.sqrt(30)
print math.sqrt(123)
print math.sqrt(80)

from math import sqrt
print sqrt(21)
print sqrt(90)
print sqrt(70)
"""

#Take vacation project
def hotel_cost(nights):
    return nights*90
def bus_ticket_cost(city):
    if city=="buchanan":
        return 245
    elif city=="kakata":
        return 180
    elif city=="zwedru":
        return 742
    elif city=="happer":
        return 1230
def rental_bike_cost(days):
    per_day=days*40
    if days>3:
        return per_day-20
    elif days>=7:
        return per_day-50
    else:
        return per_day
def trip_cost(city,days,spending_money):
    return rental_bike_cost(days)+hotel_cost(days)+bus_ticket_cost(city)+spending_money
print trip_cost("zwedru",5, 200)
   


Intermediate

# intermediate python day 1: General Review
#q4
water="fishman"
print water

rate=79.5
print rate

pan=10+10
print pan

box=12<6
print box

#q5
print len('electrification')

#q6
business=raw_input("what is your name")
print "hello%s you i welcome to my home' % busines"
#q7
LIB_weather=raw_input("what is the weather ?")
weather_R="dry season"
weather_S="rainy season"
if LIB_weather==weather_R:
    print" you need umbrella"
elif LIB_weather==weather_S:   
    print "yes need a umbrella n Tshirt"
else:
 print "this weather is in LIB"
#q8
 print not not not false
#q9
print 510+12!=600-78
#q10
print"personification"[7]
#q11
print "freedom".upper()
#q12
from datetime inputdatetime
current_datetime=date.now()
"""



     
# this code will be squared number

def squared_num(z):
    print z**2

squared_num(6)

#this fnctxn defining modulus
def draperc (b,d):
    print b&d
draperc(31,5)

#generate run fnctxn it should 3arg
def math(E2,E3,E4):
    print E2-E3-E4
math (100,90,80)

#4 creata function call transport

def transport(taxi,bike,canon):
    print taxi+bike+canon
transport (12,11,3)

#5
def moving_on(x,y):
    x=7
    y=8
    return x+y
print moving_on(7,8)


#
def moving_on(x,y):
    return x+y
moving_here=moving_on(7,8)
print moving_here
   



  


         
    
  

Friday 2 August 2013

working with comparetor in boolean

10==11-1
print 10==11-1

20==19+1
print 20==19+1

15==3*5
print 15==3*5

print 10==20/2

print 3!=8

print 25>7
print 2<8

print 2>=0

print 3<=6

print not not not False

print False and False

print -3==-3 and 5>=10

print 20<=-3 or False

print -10 or -10
100 or 100
print 3>7 or 5>15

print not 5*5<25

print not 8/2>4

print False or not True and True

print False and not True or True

print True and not (False or False)

print not not True or False and not True




















Monday 22 July 2013

working with data type,string

# working with strings
brain="always look on the bright side of life"
print brain

Sunday="i spent my Sunday very well at my church"
print Sunday

uncle="Johnson"
aunty="hawa"
brother="henneh"

print aunty
quote="our trainer\'s health has been restored!"
print quote


rose="i\'m sad that sau\'s school is close"
print rose

print "python"[4]

print "yarkpawolobuluka"[10]

#working with string methods

par not="Norwegian Blue"
print Len(par not)

small_letter=par not.lower()
print small_letter

big_letter=small_letter.upper()


print big_letter
pi=3.4
total=str(pi)
print total

# working with advance print

breakfast="spam" + " and " + "egg"
print breakfast

uncle="Johnson"
print "my father brother is" + uncle


Friday 12 July 2013

learning variables in datetype

#my variables

cup="water"
print cup

room="chair"
print room

house="people"
print house

rose="sackie"
print rose

tree="apple"
print tree

father="son+daughter"
print father

money="credit"
print money

month="may"
print month


#my type calculator

pizza=17.40
tax=0.03
tip=0.15
lunch=pizza+pizza*tip
payment=lunch+pizza*tip
print payment

Wednesday 10 July 2013

welcome to my blog

By the way i an miss Rose S. Sackie, live in Liberia with my parent. I was born unto the union of Mr & Mrs sackie, on February 3,1992. Alone with one sister.