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.
>>>
No comments:
Post a Comment