Friday, May 31, 2013

LIST LESSON

In Python, a list stores a collection of different pieces of information as a sequence under a single variable name.
For example: grocery_list = [“Milk”, “Eggs”, “Rice”,
There are few code below:
 Learning Python
Lesson 6 : Lists & Dictionaries
List Functions

Simple programming exercises from Codecademy
"""


# Exercise 0 : Appending & List Length
"""
    Append 3 more items to the suitcase list.
    Then, set list_length equal to the length of suitcase.
"""

suitcase = []
suitcase.append("sunglasses")

# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")

suitcase.append("beachwear")
suitcase.append("T-Shirt")
suitcase.append("laptop")


# Create a variable called list_length and assign it to the length of suitcase
list_length = len(suitcase)


print "There are %d items in the suitcase." % list_length
print suitcase

Answer found below:
Learning Python
Lesson 6 : Lists & Dictionaries
List Functions

Simple programming exercises from Codecademy
"""


# Exercise 0 : Appending & List Length
"""
    Append 3 more items to the suitcase list.
    Then, set list_length equal to the length of suitcase.
"""

suitcase = []
suitcase.append("sunglasses")

# Append 3 more items to the suitcase
suitcase.append("hat")
suitcase.append("shorts")
suitcase.append("shoes")

suitcase.append("beachwear")
suitcase.append("T-Shirt")
suitcase.append("laptop")


# Create a variable called list_length and assign it to the length of suitcase
list_length = len(suitcase)


print "There are %d items in the suitcase." % list_length
print suitcase

Completion of Vacation trip.

I learned on how to plan for a trip through programming.

The vacation trip code below:
"""
Learning Python
Lesson 5 : Functions
Taking a Vacation

Simple programming exercises from Codecademy
"""


# Exercise 0 : Planning Your Trip
"""
    First, write a function called hotel_cost that takes the
    variable nights as input. The function should return how
    much you have to pay if the hotel costs 140 dollars for
    every night that you stay.
"""
def hotel_cost(nights):
    return nights * 140

# Exercise 1 : Getting There
"""
    Write a function called plane_ride_cost that takes a
    string, city, as input. The function should return a
    different price depending on the location. Below are
    the valid destinations and their corresponding round-trip prices.

    "Paris": 183
    "New York": 220
    "Tokyo": 222
    "Istanbul": 475
"""
def plane_ride_cost(city):
    if city == "Paris":
        return 183
    elif city == "New York":
        return 220
    elif city == "Tokyo":
        return 222
    else:
        return 475
   
           
# Exercise 2 : Transportation
"""
    Write a function called rental_car_cost that takes days
    as input and returns the cost for renting a car for said
    number of days. The cost must abide by the following conditions:

    Every day you rent the car is $40.

    If you rent the car for 3 or more days, you get $20 off your total.

    If you rent the car for 7 or more days, you get $50 off your total.
    (This does not stack with the 20 dollars you get
    for renting the car over 3 days.)

"""
def rental_car_cost(days):
    raw_cost = days * 40

    if days >= 3 and days < 7 :
        return raw_cost - 20
    elif days >= 7:
        return raw_cost - 50
    else:
        return raw_cost
       
   
# Exercise 3 : Pull it Together
"""
    Now write a function called trip_cost that takes two inputs,
    city and days. city should be the city that you are going to
    visit and days should be the number of days that you are staying.

    Have your function return the sum of the rental_car_cost,
    hotel_cost, and plane_ride_cost functions with their respective inputs.
"""
def trip_cost(city, days, spending_money):
    return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
       





# Exercise 4 : Expect the Unexpected
"""
    Make it so that your trip_cost function takes a third parameter,
    spending_money. Just modify the trip_cost function to do just as
    it did before, except add the spending money to the total that it
    returns.
"""



# Exercise 5 : Let's go!
"""
    Now that you have it all together, print out the cost of a trip
    to "New York" for 5 days with an extra 200 dollars of spending money.
"""
print trip_cost("New York", 5, 200)

print trip_cost("Istanbul", 10, 100)

print trip_cost("Tokyo", 2, 400)

print trip_cost("Paris", 2, 400)

The answer found below:
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2

1300

Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 4 : Test Passed!
>>>
1300
2325

Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 4 : Test Passed!
>>>
1300
2325
3122

Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 4 : Test Passed!
>>>
1300
2325
3122
943

Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 4 : Test Passed!
>>>
1300
2325
982
943

Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 4 : Test Passed!

Wednesday, May 29, 2013

My Python Class today, May 29ht, 2013 was really good.

Then print type2

    Create a variable called type3 and set it to the type of an string
    Then print type3
"""

# Here's an example for you:
type0 = type(True)
print type0

type1 = type(30)
print type1

type2 = type(6.8)
print type2

type3 = type ("Enjoying my python class !")
print type3

Learning Python
Lesson 5 : Functions
Importing Modules

Simple programming exercises from Codecademy
"""


# Exercise 0 : Generic Imports
"""
    Type import math
    Print the square root of 25
    For example, print math.sqrt(36) will print 6.0
"""

from math import*
print sqrt(144)

# Exercise 1 : Function Imports
"""
    Change the import so that you only import the sqrt function, like this:
    from math import sqrt
    Print the square root of 100
    For example, print sqrt(81) will print 9.0
"""





# Exercise 2 : Function Imports
"""
    Change the import so that you import everything from the math module, like this:
    from math import *
    Print the square root of 144
    For example, print sqrt(25) will print 5.0
"""



These are few answers from this class.
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
10
>>>
10
7
>>>
10
They are equal
>>>
10
87
>>>
10
-10
10
<type 'bool'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Failed!
Exercise 2 : Test Failed!
Exercise 3 : Test Failed!
Exercise 4 : Test Failed!
>>>
10
-10
10
9
<type 'bool'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Failed!
Exercise 3 : Test Failed!
Exercise 4 : Test Failed!
>>>
10
-10
10
9
-5
<type 'bool'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Failed!
Exercise 4 : Test Failed!
>>>
10
-10
10
9
-5
42
<type 'bool'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4 : Test Failed!
>>>
10
-10
10
9
-5
42
<type 'bool'>
<type 'int'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4 : Test Failed!
>>>
10
-10
10
9
-5
42
<type 'bool'>
<type 'int'>
<type 'float'>
<type 'str'>

Here are the results of Lesson 5: Functions
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4 : Test Passed!
>>>
6.0

>>>
5.0


10.0

>>>
10.0

>>>
12.0


Monday, May 27, 2013

FUNCTIONS LESSON

Introduction to Functions
Υ
We do two things with functions:
Declare
Functions
def add_one(x):
return x + 1
"""
Learning Python
Lesson 5 : Functions
Function Syntax

Simple programming exercises from Codecademy
"""


# Exercise 0 : Function Junction
"""
    Write a function description as a comment
    Create a function called spam
    The function should print "Eggs!" when it is called.
"""

# Write a function description here and your function below!
#Print "Egg!" when called
def spam():
    print "Eggs !"


spam()



# Exercise 1 : Call and Response
"""
    Below is a function called square.
    Call the function and give it the argument 10
"""

# square(n) -> Takes a number and prints its value squared
def square(n):
    """Returns the square of a number."""
    squared = n**2
    print "%d squared is %d." % (n, squared)
    return squared

# Call the function square() below and give it the number 10

square(50)




# Exercise 3 : Functions calling functions
"""
        Check out the two functions in the editor:
        one_good_turn and deserves_another.
        The first function adds 1 to number it gets as an argument,
        and the second adds 2.

        In the body of deserves_another, change the function so
        that it always adds 2 to the output of one_good_turn.

        Print the result of calling deserves_another on the number 1.
        What do you think the result will be?
"""

def first_one(z):
    return z + 1
  
def second_one(n):
    return first_one(5) + 2

print second_one(5)



# Exercise 4 : Practice Makes Perfect
"""
        Define a function called cube that takes a number
        and returns the cube of that number.
        (Cubing a number is the same as raising it to the third power).

        Define a second function called by_three that takes one number
        as an argument. If that number is evenly divisible by 3,
        by_three should call cube on that number.
        If the number is not evenly divisible by 3,
        by_three should return False.
"""
#Cube a given number!

def by_three(n):
    if n%3 == 0:
        return cube(n)
  
    else:
        return False
  
print by_three(3)
print by_three(7)

Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
Eggs !
>>>
Eggs !
50 squared is 2500.
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
5
>>>
Eggs !
50 squared is 2500.
8
125
>>>
Eggs !
50 squared is 2500.
8
125
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
27
>>>
Eggs !
50 squared is 2500.
8
False
>>>
Eggs !
50 squared is 2500.
8
>>>
Eggs !
50 squared is 2500.
8
27
False
>>> 


COMPLETION OF THE PIG LATIN WORK/LESSON.

When you think you've got it, SAVE and RUN your program and test it out!
"""
pyg = "ay"

if len(original) > 0 and original.isalpha():
     word = original.lower()
     first = word[0]

     if first == "a" or first == "e" or first == "i" or first == "o" or first == "u":
         print word + pyg
     else:

         rest = word[1:]
         print rest + first + pyg
        
    
else:
     print "empty"
    
Answer found below
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Apple
Apple
vowel
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Bird
Bird
consonant
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: egg
egg

Welcome to the English to Pig Latin translator!
Please input an English word: egg
eggay
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: snake
nakesay
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Mary
arymay
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Agriculture
agricultureay
>>>
Welcome to the English to Pig Latin translator!
Please input an English word:

Friday, May 24, 2013

If, Elif, Else Lesson continue

If.
  • Test a condition to see if it's true
    • if age <18:
    • if name == "Zane":
  • Only one of these per if/elif/else 
"""
Learning Python
Lesson 4 : Conditionals and Control Flow
If, Else and Elif
Simple programming exercises from Codecademy
"""


# Exercise 0 : Conditional Statement Syntax
"""
    What do you think will happen in the 3 lines of code below?
"""

answer = "Left"
if answer == "Left":
    print "You are correct!"



# Exercise 1 : Create Your Own Conditional Statements
"""
    Uncomment the code below and write
    an if statement that returns True.

    Then print the result of the function like this:
    print true_function()
"""




def true_function():
    if 5 == 4 + 1 :              # Fill in your if statement here!
        return True         # Make sure this returns True

print true_function()



# Exercise 2 : Else Problems
"""
    Complete the if/else statements below.

    When you're done print the result of black_night()
    and then print the result of french_soldier()
"""


answer = "'Tis but a scratch!"

def black_knight():
    if answer == "'Tis but a scratch!":
        return True             # Make sure this returns True
    else:                 
        return False            # Make sure this returns False

def french_soldier():
    if answer == "Go away, or I shall taunt you a second time!":
        return True            # Make sure this returns True
    else:                 
        return False            # Make sure this returns False


print french_soldier()

   

# Exercise 3 : Elif Problems
"""
    Fill in the elif statement so that it
    returns True for the answer "I like Spam!"
"""

answer = "I like Spam!"

def feelings_about_spam():
    if answer == "I hate Spam!":
        return False
    elif answer == "I like Spam!":                   # Write a statement to check the answer variable
        return  True             # Make sure this returns True
    else:
        return False             # Make sure this returns False


# ************************************************************
# TESTS : DO NOT MODIFY THESE
# ************************************************************

 ANSWER ARE FOUND BELOW:

Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
You are correct!
True
>>>
You are correct!
True
False
>>>
You are correct!
True
False
>>>
You are correct!
True
False
>>>

"""
Learning Python
Lesson 4 : Conditionals and Control Flow
English to Pig Latin Translator

This program will tranlates English words typed in by the user
and will translate them into Pig Latin
"""


# Exercise 0 : Welcome!
"""
    Write a print statement that says "Welcome to the English to Pig Latin translator!"
"""
print "Welcome to the English to Pig Latin translator!"




# Exercise 1 : User Input
"""
    Now we need to get input from the user. We can do it like this:
    var = raw_input("Insert message here...")
    Create your own user input statement.
    Instead of "var", name your variable "original"
    and make the message say "Please input an English word: "
"""
original = raw_input ("Please input an English word: ")
print original




# Exercise 2 : Check the input
"""
    Write an if statement that checks to see if the string is not empty.

    If the string is not empty, print the user's word.
    Otherwise (else), print "empty" if the string is empty.

    HINT: You can check to see if the string is empty by getting its length
          For example, len("HELLO") is 5
                       len("") is 0

    When you think you've got it, SAVE and RUN your program and test it out!
"""
pyg = "ay"

if len(original) > 0 and original.isalpha():
     word = original.lower()
     first = word[0]

     if first == "a" or first == "e" or first == "i" or first == "o" or first == "u":
         print "vowel"
     else:
         print "consonant"
      
else:
     print "empty"
    





# Exercise 3: More checking
"""
    Pig Latin only works with words, so we need to check if the user
    typed in a word or something like 238asdf23819.

    Thankfully, Python can check for this using the isalpha() function.
    Modify your if statement to look like this and test it out:

    if len(original) > 0 and original.isalpha():

    Make sure you SAVE, RUN and test it out before moving on.

"""


# Exercise 4: Adding the "ay"
"""
    Write the following code BEFORE your if statement:
   
    Create a variable named pyg and set it equal 'ay'.

    Convert what's stored in the variable 'original' to
    all lowercase letters and store it as the variable 'word'

    Create a new variable called "first" and set it to the first letter of
    the variable "word"

"""


# Exercise 5: Checking for Vowels
'''
    If the user's word starts with a vowel (a,e,i,o,u), you just add "ay" to the end
    For example, "apple" becomes "appleay"

    If the user's word starts with anything else, you move the first letter of the word
    to the end and add "ay"
    For example, "banana" becomes "ananabay"

    Let's check to see if the users word starts with a vowel.
    Add a new if/else block nested inside of your existing one.

    The new if should check to see if the first letter of word is a vowel.
    If it is, your code should print "vowel".
    If the first letter of word is not a vowel,
    your code should print "consonant".

    You can remove the "print original" line from your code.  
'''
THE CLASS STOPPED THIS LESSON TO LESSON 6

# Exercise 6: appleay!
'''
    Now it's time to translate a little bit.
    If the word typed by the user is a vowel, translating is easy!

    Create a variable called 'new_word' that contains the result of
    appending "ay" to the end of the word.
    Remember you created a pyg variable that stores the "ay" string

    Replace the "print 'vowel'" text and print the 'new_word' variable instead   
'''

# Exercise 7: ogday!
'''
    Inside the else part of your if/else block that checks the first letter of the word,
    set the new_word variable equal to the translation result for a word that starts with a consonant.

    Remember, you want to take the whole word (without the first letter) and append the first letter
    to the end, and then append "ay" to the end of that.

    Create a variable called rest and set it to the rest of the word (without the first letter)

    To get the whole word without the first letter, you can slice it using the pattern s[i:j].
    For example, if s = "foo", then s[1] gives you "oo"

    Replace the print 'consonant' bit with print new_word. Make sure to test your code
    with a word that starts with a consonant!
'''

# Exercise 8: Testing, testing!
'''
    Make sure you test your program several times and use different kinds of input.
    You never know what people will type, so try lots of things (numbers, letters, symbols)
    to make sure that it works properly!
'''


    ANSWER ARE FOUND BELOW TOO:

Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
You are correct!
True
>>>
You are correct!
True
False
>>>
You are correct!
True
False
>>>
You are correct!
True
False
>>>
Welcome to the English to Pig Latin translator!
>>>
Welcome to the English to Pig Latin translator!
You will enjoy the Pig Latin translator

>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Apple
Apple
Apple
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: 1212121
1212121
empty
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Apple
Apple
Apple

>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Apple
Apple
Apple

Welcome to the English to Pig Latin translator!
Please input an English word: Air
Air
Air

Welcome to the English to Pig Latin translator!
Please input an English word: Air
Air
Air
vowel
>>>
Welcome to the English to Pig Latin translator!
Please input an English word: Bird
Bird
consonant
>>>

Wednesday, May 22, 2013

What I learned in my python class today (May 22, 2013)

I started up with lesson 3 and went up lesson 4 Lesson 4 : Conditionals and Control Flow
Boolean Operators.
 


"""
Learning Python
Lesson 3 : Strings
Advanced Printing
Simple programming exercises from Codecademy
"""


# Exercise 0 : String Concatenation
"""
    Create a variable called breakfast and set it to the
    concatenated strings "Spam ", "and ", "eggs".
    Then print breakfast to the interactions window.
"""
breakfast = "Spam " + "and " + "eggs"
print breakfast






# Exercise 1 : Explicit String Conversion
"""
    Uncomment the print statement below, SAVE and RUN.
    What happens?
    Use str() to turn 3.14 into a string and SAVE and RUN again.
"""

print "The value of pi is around " + str(3.14)






#Exercise 2 : String Formatting with %, Part 1
"""
    Uncomment the print statement below (Remove the # symbol).
    What do you think it'll do?
    Once you think you know, SAVE and RUN.
"""

string_1 = "Camelot"
string_2 = "place"

print "Let\'s not go to %s. \'Tis a silly %s." % (string_1, string_2)






# Exercise 3 : Print Formatting
"""
For our grand finale, we're showing you a bit of new code.
Don't worry if you don't get how it works yet; we'll explain it soon!

Uncomment the lines below and replace the ___s with the form of %
you need to complete your quest:

%s inside the string, and % to link the string with its arguments.
Answer the questions in the console as they pop up!
"""




name = raw_input("What is your name?")
quest = raw_input("What is your quest?")
color = raw_input("What is your favorite color?")

print "Ah, so your name is %s, your quest is %s, and your favorite color is %s." % (name, quest, color)






# ************************************************************
# TESTS : DO NOT MODIFY THESE
# ************************************************************

Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
Spam and eggs
The value of pi is around 3.14
Let's not go to Camelot. 'Tis a silly place.
What is your name? Joseph M Konneh
What is your quest? Learning
What is your favorite color? Green
Ah, so your name is  Joseph M Konneh, your quest is  Learning , and your favorite color is  Green.
>>>

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Failed!
Exercise 1 : Test Failed!
>>>
0
0
0
0
0
0
>>>
True
False
True
False
True
False

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!

"""
Learning Python
Lesson 4 : Conditionals and Control Flow
Comparators
Simple programming exercises from Codecademy
"""

# IGNORE THIS CODE
# *******************************************************************************************************************************************************
bool1 = bool2 = bool3 = bool4 = bool5 = bool6 = bool7 = bool8 = bool9 = bool10 = bool11 = 0
# *******************************************************************************************************************************************************




# Exercise 0 : Compare closely!
"""
    Set each variable to either True or False depending on what you
    think the result of the evaluation above it will be.
    For example, 1 < 2 will be True, because one is less than two.
   
"""
# Look at the expression below and set bool0 to True or False
# EXAMPLE: 4 == 5 - 1
bool0 = True

# Look at the expression below and set bool1 to True or False
# 17 < 118 - 100
bool1 = True


# Look at the expression below and set bool2 to True or False
# 100 == 33 * 3 + 1
boo12 = True


# Look at the expression below and set bool3 to True or False
# 10 <= 3**2
boo13 = False


# Look at the expression below and set bool4 to True or False
# -22 >= -18
boo14 = False


# Look at the expression below and set bool5 to True or False
# 99 != 98 + 1
boo15 =  False




# Exercise 1 : Turned Tables
"""
    Uncomment each boolean variable and write an expression
    that evaluates to that value. Feel free to write expressions
    that are as simple or as complex as you'd like!
    Remember, though: simple is better than complex!

    Remember, comparators are: ==, !=, >, >=, <, and <=.
"""

# EXAMPLE: Set bool0 equal to a True comparison using ==
bool0 = (4 == 2 + 2)


# Set bool6 equal to a True comparison using ==
bool6 = (6 == 4 + 2)
print bool6


# Set bool7 equal to a False comparison using !=
bool7 = (15 != 5 + 10)
print bool7


# Set bool8 equal to a True comparison using >
bool8 = (23 > 7 + 10)
print bool8


# Set bool9 equal to a False comparison using >=
bool9 = (12 >= 22 + 1)
print bool9


# Set bool10 equal to a True comparison using <
bool10 = (22 < 22 + 12)
print bool10


# Set bool11 equal to a False comparison using <=
bool11 = (12 <= 2)
print bool11









# ************************************************************
# TESTS : DO NOT MODIFY THESE
# ************************************************************

print("")
print("Here are the results of Lesson 4: Conditionals")
if bool1 and bool2 and not bool3 and not bool4 and not bool5 : print("Exercise 0 : Test Passed!")
else: print("Exercise 0 : Test Failed!")
if bool6 and not bool7 and bool8 and not bool9 and bool10 and not bool11: print("Exercise 1 : Test Passed!")
else: print("Exercise 1 : Test Failed!")

   
"""
Learning Python
Lesson 4 : Conditionals and Control Flow
Boolean Operators
Simple programming exercises from Codecademy
"""

# IGNORE THIS CODE
# *******************************************************************************************************************************************************
bool1 = bool2 = bool3 = bool4 = bool5 = bool6 = bool7 = bool8 = bool9 = bool10 = bool11 = bool12 = bool13 = bool14 = bool15 = bool16 = 0
# *******************************************************************************************************************************************************


# Exercise 0 : AND
"""
    Let's practice a bit with and. Assign the boolean values
    beneath each expression as appropriate. This may seem overkill,
    but remember: practice makes perfect.
"""
# EXAMPLE: Look at the expression below and set bool0 to True or False
# True and False
bool0 = False


# Look at the expression below and set bool1 to True or False
# False and False
bool1 = False


# Look at the expression below and set bool2 to True or False
# -2 == -2 and 4 >= 16
bool2 = False


# Look at the expression below and set bool3 to True or False
# 1 <= 2 and True
bool3 = True


# Look at the expression below and set bool4 to True or False
# True and True
bool14 = True




# Exercise 1 : OR
"""
    Time to practice with or!
"""

# Look at the expression below and set bool5 to True or False
# 3 - 1 == 4 / 2 or 'Cleese' == 'King Arthur'
bool5 = True


# Look at the expression below and set bool6 to True or False
# True or False
bool6 = True


# Look at the expression below and set bool7 to True or False
# 10 <= -1 or False
bool7 = False


# Look at the expression below and set bool8 to True or False
# True or True
bool8 = True



# Exercise 2 : NOT
"""
    Last but not least, let's get some practice in with not.
"""
# Look at the expression below and set bool9 to True or False
# not True
bool9 = False


# Look at the expression below and set bool10 to True or False
# not 3 * 4 < 12
bool10 = True


# Look at the expression below and set bool11 to True or False
# not 0 <= 5 - 6
bool13 = True


# Look at the expression below and set bool12 to True or False
# not not False
bool14 = False




# Exercise 3 : This & That
"""
    Uncomment the variables below and assign True or False as appropriate
    Remember the order:
        1. ( )
        2. not
        3. and
        4. or
"""

# Look at the expression below and set bool13 to True or False
# False or not True and True
# False or False and True
# False or False
# False
bool13 = False


# Look at the expression below and set bool14 to True or False
# False and not True or True
bool14 = True


# Look at the expression below and set bool15 to True or False
# True and not (False or False)
bool15 = True


# Look at the expression below and set bool16 to True or False
# not not True or False and not True
bool16 = True




# ************************************************************
# TESTS : DO NOT MODIFY THESE
# ************************************************************

print("")
print("Here are the results of Lesson 4: Conditionals")
if not bool1 and not bool2 and bool3 and bool4 : print("Exercise 0 : Test Passed!")
else: print("Exercise 0 : Test Failed!")

if bool5 and bool6 and not bool7 and bool8 : print("Exercise 1 : Test Passed!")
else: print("Exercise 1 : Test Failed!")

if not bool9 and bool10 and bool11 and not bool12 : print("Exercise 2 : Test Passed!")
else: print("Exercise 2 : Test Failed!")

if not bool13 and bool14 and bool15 and bool16 : print("Exercise 3 : Test Passed!")
else: print("Exercise 3 : Test Failed!")

   
Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
Spam and eggs
The value of pi is around 3.14
Let's not go to Camelot. 'Tis a silly place.
What is your name? Joseph M Konneh
What is your quest? Learning
What is your favorite color? Green
Ah, so your name is  Joseph M Konneh, your quest is  Learning , and your favorite color is  Green.
>>>

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Failed!
Exercise 1 : Test Failed!
>>>
0
0
0
0
0
0

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Failed!
Exercise 1 : Test Failed!
>>>
True
False
True
False
True
False

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Failed!
Exercise 1 : Test Passed!
>>>

Here are the results of Lesson 4: Conditionals
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
>>>

Members of Room 12, Special Corps, Liberia National Police


Members of Room 12 of the Special Corps during the training of

Monday, May 20, 2013



I am very glade to be part of this python class for today, May 20th, 2013.
I learned a lot today, below arethe details:
Instructor Zane Cocchran started up with our last class lesson 2 Tip Calculator and went up to the math Operators wherein I learned how to add, subtract, multiply, divide, exponants and modules.

  • I also learned String methods in this methods are pre-built pieces of code that the program used
  • make certain tasks easier
  • and they are quick to used.
    • len() this has to do with numbers
    • lower() this hasto do with small letter joseph
    • upper()this has to do with capital letter JOSEPH
    • str() this hasto do with age 34yrs

Also learned about Advanced Printing
Advanced Printing
e String Formatting
dessert_1 = cake
dessert_2 = cookies
print ”I like %s and %s" %
(dessert_1 , dessert_2 )
⇒ “I like cake and cookies”

These are examples of what I learned onthis day (20-05-2013) below.


Learning Python
Lesson 2 : Tip Calculator
Simple programming project from Codecademy

We're going to create a tip calculator for when we eat at a restaraunt.
This will help us determine what our final bill is after we eat.

"""


# Create a variable meal and assign it the value 44.50.
meal = 44.50




# Create a variable tax and set it equal to the decimal value of 6.75%.
# Hint: 6.75% is 0.0675
tax = 0.0675

# Set the variable tip to 15% (in decimal form!).
tip = 0.15


# Reassign meal to the value of itself + itself * tax
# (This will add the dollar amount of the tax to the cost of the meal)
meal = meal + meal * tax


# Assign the variable total to the sum of meal + meal * tip
# print the variable total
# Hint: to print the variable total, type: print total
# SAVE and RUN to see the total cost of your meal!
total = meal + meal * tip
print total


Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "copyright", "credits" or "license()" for more information.
==== No Subprocess ====
>>>
3
3
20
2
25
1

Here are the results of Lesson 2
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4 : Test Passed!
Exercise 5 : Test Passed!
>>>
54.6293125
>>>


"""
Learning Python
Lesson 3 : Strings
Simple Strings
Simple programming exercises from Codecademy
"""

# IGNORE THIS CODE
# ***************************************************************
brian = caesar = praline = viking = quote = substring = 0
# ***************************************************************




# Exercise 0 : Getting started with Strings
"""
    Assign the string "Always look on the bright side of life!"
    to the variable brian.
"""
brian = "Always look on the bright side of life!"





# Exercise 1 : Multi-Line Comments
"""
    Set caesar to "Graham"
    Set praline to "John"
    Set viking to "Teresa"
"""
caesar = "Graham"
praline = "John"
viking = "Teresa"



# Exercise 2 : Escape Characters
"""
    Assign the value: 'Help! Help! I'm being repressed!'
    to the variable quote. Remember to use an escape character
"""
quote = 'Help! Help! I\'m being repressed!'




# Exercise 3 : Accessing Characters
"""
    The string "PYTHON" has six characters,
    numbered 0 to 5, as shown below:

    ---+---+---+---+---+---+-
     P | Y | T | H | O | N |
    ---+---+---+---+---+---+-
     0   1   2   3   4   5

    So if you wanted "Y", you could just type
    "PYTHON"[1] (always start counting from 0!)

    Assign the 4th letter of "PYTHON" to the variable substring
"""
substring = "PYTHON"[3]
print substring



Here are the results of Lesson 3: Strings
Exercise 0 : Test Passed!
Exercise 1 : Test Failed!
Exercise 2 : Test Failed!
Exercise 3 : Test Failed!
>>>

Here are the results of Lesson 3: Strings
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Failed!
Exercise 3 : Test Failed!
>>>

Here are the results of Lesson 3: Strings
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Failed!
>>>

Here are the results of Lesson 3: Strings
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Failed!
>>>
H

Here are the results of Lesson 3: Strings
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
>>>


"""
Learning Python
Lesson 3 : Strings
String Methods
Simple programming exercises from Codecademy
"""

# IGNORE THIS CODE
# *********************************************************************************
parrot = small_parrot = big_parrot = pi_string = pi = 0
color_length = color_big = color = ""
# ********************************************************color*************************


# Exercise 0 : len()
"""
    Create a variable called parrot and set it to the string "Norwegian Blue"
    Be sure to include the space and capitalize exactly as shown!

    Then type len(parrot) after the word print, like so: print len(parrot).
    This will print out the number of letters in "Norwegian Blue"
"""
parrot = "Norwegian Blue"
print len (parrot)







# Exercise 1 : lower()
"""
    Python is all about automation! Create a new variable called
    small_parrot and call lower() on parrot, like this : small_parrot = parrot.lower()
    Then print the variable small_parrot
"""
small_parrot = parrot.lower()
print small_parrot





# Exercise 2 : upper()
"""
    Now you want to make it all uppercase!
    Create a variable called big_parrot and call upper() on it.
    Then print the variable big_parrot.
"""
big_parrot = parrot.upper()
print big_parrot






# Exercise 3 : str()
"""
    Create a variable pi and set it to 3.14.
    Then create a variable called pi_string and
    set it equal to str(pi).
    Print pi_string
"""
pi = 3.14
pi_string = str(pi)
print pi_string



# Exercise 4 : More Practice
"""
    Let's do just a bit more practice.
    Create a variable called color and set it to your favorite color
    Print the variable color
    Create a variable called color_length and set it to the len() of color
    Print the variable color_length
    Create a variable called color_big and set it to the upper() of color
    Print the variable color_big  
"""
color = "Green"
print color
color_length = len('color')
print color_length
color_big = color.upper()
print color_big


Here are the results of Lesson 3: String Methods
Exercise 0 : Test Passed!
Exercise 1 : Test Failed!
Exercise 2 : Test Failed!
Exercise 3: Test Failed!
Exercise 4: Test Failed!
>>> 
14

norwegian blue

norwegian blue
NORWEGIAN BLUE

Here are the results of Lesson 3: String Methods
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3: Test Failed!
Exercise 4: Test Failed!
>>> 
14
norwegian blue
NORWEGIAN BLUE
3.14

Here are the results of Lesson 3: String Methods
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4: Test Failed!
>>> 
14
norwegian blue
NORWEGIAN BLUE
3.14
Green
5
GREEN

Here are the results of Lesson 3: String Methods
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Passed!
Exercise 3 : Test Passed!
Exercise 4 : Test Passed!
>>> 

"""
Learning Python
Lesson 3 : Strings
Advanced Printing
Simple programming exercises from Codecademy
"""


# Exercise 0 : String Concatenation
"""
    Create a variable called breakfast and set it to the 
    concatenated strings "Spam ", "and ", "eggs".
    Then print breakfast to the interactions window.
"""
breakfast = "Spam " + "and " + "eggs"
print breakfast






# Exercise 1 : Explicit String Conversion
"""
    Uncomment the print statement below, SAVE and RUN.
    What happens?
    Use str() to turn 3.14 into a string and SAVE and RUN again.
"""

print "The value of pi is around " + str(3.14)






# Exercise 2 : String Formatting with %, Part 1
"""
    Uncomment the print statement below (Remove the # symbol).
    What do you think it'll do?
    Once you think you know, SAVE and RUN.
"""

string_1 = "Camelot"
string_2 = "place"

print "Let\'s not go to %s. \'Tis a silly %s." % (string_1, string_2)

Answer:
Spam and eggs
>>> 
Spam and eggs
The value of pi is around 3.14
>>> 
Spam and eggs
The value of pi is around 3.14
Let's not go to Camelot. 'Tis a silly place.
>>>




Friday, May 17, 2013

What did learn about today?
In my second day of lesson in this python class, I learned a lot about the following below:
  • Variables & Data type -
    • Variables is the one of the most common concepts of programming,
    • Data Types is in four faces in that there is
      •  Integer (Int): These are whole number and Negative or positive. Example 26, -56
      • Floating points (float) These are numbers with Desmond number. Example 1.34
      • Boolean These are true or false value. Example Liberian
      • String these are words and this is the only data type that goes.  with cotation. Example "Hello"
    •  
  • Whitespace & Statements
    • White space does matters in programming.
  • Comments- in commits, there were two things that i learned in that you can start a simple commits with hatch # and in double commits you can used single or double codes 
  • What kinds of programs did you write?
    • They are as below:
      • GCC 4.6.3] on linux2
        Type "copyright", "credits" or "license()" for more information.
        ==== No Subprocess ====
        >>>
        Welcome to Python!

        Here are the results of Lesson 2
        Exercise 0 : Test Passed!
        Exercise 1 : Test Failed!
        Exercise 2 : Test Failed!
        Exercise 3 : Test Failed!
        >>> Print "Hello world"
        SyntaxError: invalid syntax
        >>> print "Hello world!"
        Hello world!
        >>>
        Welcome to Python!

        Here are the results of Lesson 2
        Exercise 0 : Test Passed!
        Exercise 1 : Test Passed!
        Exercise 2 : Test Failed!
        Exercise 3 : Test Failed!
        >>>
        Welcome to Python!

        Here are the results of Lesson 2
        Exercise 0 : Test Passed!
        Exercise 1 : Test Passed!
        Exercise 2 : Test Failed!
        Exercise 3 : Test Failed!
        >>>
        Welcome to Python!

        Here are the results of Lesson 2
        Exercise 0 : Test Passed!
        Exercise 1 : Test Passed!
        Exercise 2 : Test Passed!
        Exercise 3 : Test Failed!
        >>>
        Welcome to Python!
        7
        3

        Here are the results of Lesson 2
        Exercise 0 : Test Passed!
        Exercise 1 : Test Passed!
        Exercise 2 : Test Passed!
        Exercise 3 : Test Passed!
        >>>
        4

        Here are the results of Lesson 2
        Exercise 1 : Test Passed!
        Exercise 2 : Test Failed!
        >>>
        4
        d!
        >>>
        4

        Here are the results of Lesson 2
        Exercise 1 : Test Passed!
        Exercise 2 : Test Passed!
        >>>

Wednesday, May 15, 2013

My first python post.

My name is Joseph M Konneh,
I decided to learn python programming to help me develop my own program.
 What is program? Breaking down a complex operation into simple instructions.
Assignment # 1. Lesson1-HelloName.py


Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
What is your name? Joseph M Konneh
 Joseph M Konneh
What is your favorite colour? Green
Hello  Green!
How old are you? 32years old
Hello  32years old!
Call your phone number +231886563051
Hello  +231886563051!
Where do you live? Airfield, Sinkor
Hello  Airfield, Sinkor!
What is the name of your university? A M E Zion University
Hello  A M E Zion University!
What are names of your children? Abraham and Joseph M Konneh
Hello  Abraham and Joseph M Konneh!
Where do you worked? Profissional Standard Division, Liberia National Police, Headquarter
Hello  Profissional Standard Division, Liberia National Police, Headquarter!
What is/are your hobbit/s? Making new friends and playing soccer
Hello  Making new friends and playing soccer!
What church are a member of? Holy Innocents Parish
Hello  Holy Innocents Parish!
Which movie you like most? Season and African movies
Hello  Season and African movies!
What is your mother name? Ma Fatu Konneh
Hello  Ma Fatu Konneh!
What is your father name? D S Konneh
Hello  D S Konneh!