Monday, May 20, 2013

Day 3


Dear Readers!
It is so great to working with Python programing. Our today's lesson was focused around the following:

working with string.......that is the combination of words using quotation with spacing. we use string to construct a complete sentence.

to making my users understand my programing language.

Below are exercises.

 """
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 " + 3.14 + 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!

"""



""" <--- DELETE THIS WHOLE LINE --->

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 ___, your quest is ___, and your favorite color is ___." ___ (name, quest, color)

<--- DELETE THIS WHOLE LINE --->"""




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



"""
Learning Python
Lesson 2 : Python Syntax
Math Operations
Simple programming exercises from Codecademy
"""

# IGNORE THIS CODE
# **********************************************************************
count_to = this_sum = this_product = this_exp = this_quo = this_mod = 0
# **********************************************************************


# Exercise 0 : Arithmetic Operators
"""
    Let's start with addition.
    Set the variable count_to to the sum of 1 + 2.
    Print the variable count_to
"""

# WRITE YOUR CODE HERE

count_to = 1+2
print count_to



# Exercise 1 : Subtraction
"""
    The variable this_sum is too large!
    Tell Python to reassign this_sum to 5 - 2.
    Print the variable this_sum
"""
this_sum = 5

# WRITE YOUR CODE HERE
this_sum =5-2
print this_sum




# Exercise 2 : Multiplication
"""
    Let's try multiplication.
    Set the variable this_product to 2 * 10.
    Print the variable this_product
"""

# WRITE YOUR CODE HERE

this_product = 2 * 10
print this_product






# Exercise 3 : Division
"""
    How about division?
    Set the variable this_quo to 4 / 2.
    Print the variable this_quo
"""

# WRITE YOUR CODE HERE
this_quo = 4 / 2
print this_quo




# Exercise 4 : Exponents
"""
    Python can even square numbers!
    Set the variable this_exp to 5**2.
    Print the variable this_exp
"""

# WRITE YOUR CODE HERE
this_exp = 5**2
print this_exp




# Exercise 5 : Modulo
"""
    Modulo tells you the remainder from division. Let's give it a try!
    Set the variable this_mod to 5%2.
    Print the variable this_mod
"""

# WRITE YOUR CODE HERE
this_mod = 5%2
print this_mod




# ************************************************************
# TESTS : DO NOT MODIFY THESE
# ************************************************************
print("")
print("Here are the results of Lesson 2")
if count_to == 3: print("Exercise 0 : Test Passed!")
else : print("Exercise 0 : Test Failed!")
if this_sum == 3: print("Exercise 1 : Test Passed!")
else : print("Exercise 1 : Test Failed!")
if this_product == 20: print("Exercise 2 : Test Passed!")
else : print("Exercise 2 : Test Failed!")
if this_quo == 2: print("Exercise 3 : Test Passed!")
else : print("Exercise 3 : Test Failed!")
if this_exp == 25: print("Exercise 4 : Test Passed!")
else : print("Exercise 4 : Test Failed!")
if this_mod == 1: print("Exercise 5 : Test Passed!")
else : print("Exercise 5 : 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 ====
>>>
3

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

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

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

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 Failed!
Exercise 5 : Test Failed!
>>>
3
3
20
2
25

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 Failed!
>>>
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
>>>

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 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!
>>>

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

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
Traceback (most recent call last):
  File "/home/ilab-6/Downloads/Lesson3-StringsMethods.py", line 38, in <module>
    print small_parro
NameError: name 'small_parro' is not defined
>>>
14
norwegian blue

Here are the results of Lesson 3: String Methods
Exercise 0 : Test Passed!
Exercise 1 : Test Passed!
Exercise 2 : Test Failed!
Exercise 3: Test Failed!
Exercise 4: Test Failed!
>>>
14
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
0

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!

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




No comments:

Post a Comment