Alright continuing onto using triple quotes, I learned that you can span the lines to where text appears on the next line, like so:
message = "This line will
...span several
....lines."""
And when you tell python to print message you get:
This line will
span several
lines.
This is because you can add as much words you want to this script. Then it will only give you the prompt of >>> when you finally add the last """ to the end of your lines.
#1:
Friday, February 4, 2011
Thursday, February 3, 2011
Feb 2-3
Today I am continuing onto chapter 5. Starting with fruitful functions. When working with python on the incremental development I've noticed that the distance program they tell you to program into python is basically the same as the real life formula when you code like:
def distance(x1, y1, x2, y2):
... dx = x2 - x1
... dy = y2 - y1
... print "dx is", dx
... print "dy is", dy
... return 0.0
the d in this code is referring to distance then both the x and y used in this code stands for the x-axis and y-axis of a graph. This is a very interesting program to me and very easy to understand.
When working on getting the area of a circle i had some difficulty until I finally understand that what they was saying was to instead of start making a new program you just have to change the program you last did with distance to:
def area2(xc, yc, xp, yp)
... radius = distance(xc, yc, xp, yp)
... result = area(radius)
... return result
so basically i had to fully change the distance program to make it fit the area of a cirlce program.
When it comes to boolean functions, they are pretty easy to understand when its basically a yes/or kind of question. At this point it told me to code a small script and when I finished it came up to have an error. What caused the error which took me forever to get why it was an error was instead of using a 0 in:
def is_divisible(x, y):
return x % y = 0
I instead used an O on accident without even noticing.
When working with triple quotes, I've noticed that they work the same as just using one thing of quotes. The triple quotes still prints for example
"""Hello, world!""" when you can still use "Hello,World!" to get the same result.
def distance(x1, y1, x2, y2):
... dx = x2 - x1
... dy = y2 - y1
... print "dx is", dx
... print "dy is", dy
... return 0.0
the d in this code is referring to distance then both the x and y used in this code stands for the x-axis and y-axis of a graph. This is a very interesting program to me and very easy to understand.
When working on getting the area of a circle i had some difficulty until I finally understand that what they was saying was to instead of start making a new program you just have to change the program you last did with distance to:
def area2(xc, yc, xp, yp)
... radius = distance(xc, yc, xp, yp)
... result = area(radius)
... return result
so basically i had to fully change the distance program to make it fit the area of a cirlce program.
When it comes to boolean functions, they are pretty easy to understand when its basically a yes/or kind of question. At this point it told me to code a small script and when I finished it came up to have an error. What caused the error which took me forever to get why it was an error was instead of using a 0 in:
def is_divisible(x, y):
return x % y = 0
I instead used an O on accident without even noticing.
When working with triple quotes, I've noticed that they work the same as just using one thing of quotes. The triple quotes still prints for example
"""Hello, world!""" when you can still use "Hello,World!" to get the same result.
Tuesday, February 1, 2011
Feb 1
#4: What I've noticed from the and and or expressions is that when using or and its only True and False then True will be the result but when you exchange True or False for a number or some other word then the result with ether be True or false or the new value you've plugged in.
#5: write a program.
#6: write a program.
#7: write a program.
#8: When I put in:
if 0:
print "And now for something completely different..."
else:
print "What's all this, then?"
and then i get an end result of:
What's all this, then?
from gasp import *
begin_graphics()
Box((20, 20), 100, 100)
Box((55, 20), 30, 50)
Box((40, 80), 20, 20)
Box((80, 80), 20, 20)
Line((20, 120), (70, 160))
Line((70, 160), (120, 120))
update_when('key_pressed')
end_graphics()
#10: um I haven't fully finished this one, I'm trying to understand what they meant by instead of using both the lines instead use 2 polygons. That confuses me cause when I went to the linked site openproject.net/thinkcs/python/english2e/app_b.html. Which this site describes what your suppost 2 apply when putting a polygon in, I just cant get the end result.
OK well I've now finally catch back up with chapter 5 so ill continue onto Chapter 5 tomorrow.
#5: write a program.
#6: write a program.
#7: write a program.
#8: When I put in:
if 0:
print "And now for something completely different..."
else:
print "What's all this, then?"
and then i get an end result of:
What's all this, then?
from gasp import *
begin_graphics()
Box((20, 20), 100, 100)
Box((55, 20), 30, 50)
Box((40, 80), 20, 20)
Box((80, 80), 20, 20)
Line((20, 120), (70, 160))
Line((70, 160), (120, 120))
update_when('key_pressed')
end_graphics()
#10: um I haven't fully finished this one, I'm trying to understand what they meant by instead of using both the lines instead use 2 polygons. That confuses me cause when I went to the linked site openproject.net/thinkcs/python/english2e/app_b.html. Which this site describes what your suppost 2 apply when putting a polygon in, I just cant get the end result.
OK well I've now finally catch back up with chapter 5 so ill continue onto Chapter 5 tomorrow.
Monday, January 31, 2011
Jan 31
OK the resources ill use for my goal will be the python book provided by the class and then ill also use the How to Think Like a Computer Scientist site. My plans are by the first week or by the second week ill be caught up on my questions with my chapters and will be well onto ether chapter 7 or chapter 8. By the third week I am planning on trying to build some sort of animation or action produced through python script. Examples are maybe making a program that allows you to press any button and then after pressing the button a animation will appear on the screen or something along those lines.
Continue onto Chapter 4 questions:
#2: make a program
======================
True True True
True False False
False True False
False False False
p q not p and q
==========================
True True False
True False False
False True True
False False False
p q not(p) or not(q)
============================
True True True
True False False
False True True
False False True
p q not(p) and not(q)
============================
True True True
True False False
False True True
False False True
After a few minutes I figured what they meant by changing "p or q" to stuff like "not p and not q".
#4:
Continue onto Chapter 4 questions:
1
- >>> 5 % 2
4
- >>> 9 % 5
3
- >>> 15 % 12
12
- >>> 12 % 15
0
- >>> 6 % 6
0
- >>> 0 % 7
integer division or modulo by zero is the end result I get when i try to put 7%0 into python. Python does this because it cant get 7% of 0 when 0 has nothing in it.
- >>> 7 % 0
#2: make a program
p q not p or q ===================== True True True True False True False True True False False False
p q p and q
======================
True True True
True False False
False True False
False False False
p q not p and q
==========================
True True False
True False False
False True True
False False False
p q not(p) or not(q)
============================
True True True
True False False
False True True
False False True
p q not(p) and not(q)
============================
True True True
True False False
False True True
False False True
After a few minutes I figured what they meant by changing "p or q" to stuff like "not p and not q".
#4:
Tuesday, January 25, 2011
Jan 24-25
The name of my program/ goal for this quarter will be called "Something More"
My goal for this quarter is to for one thing improve my understanding on more on what is python. I also wanna learn, instead of the code of random programs, but more of the code for design on what picture would pop up or what action the character on the screen will do if I press like for say space. I want to have a more visceral affect this quarter to where i can actually see more then just words pop up saying some random sentence. I want to try to see if I can try to build a program or just run a program that demonstrates multiple actions and/or movements of some figure on the screen.
Um ill finish up on my resources I'll b using and my time line sometime during this week.
My goal for this quarter is to for one thing improve my understanding on more on what is python. I also wanna learn, instead of the code of random programs, but more of the code for design on what picture would pop up or what action the character on the screen will do if I press like for say space. I want to have a more visceral affect this quarter to where i can actually see more then just words pop up saying some random sentence. I want to try to see if I can try to build a program or just run a program that demonstrates multiple actions and/or movements of some figure on the screen.
Um ill finish up on my resources I'll b using and my time line sometime during this week.
Friday, January 21, 2011
Jan 21
OK well today I'm continuing on my exercises trying to catch back up to chapter 5. Um I'm starting out on chapter 2.
#5:
float
str
'The knights who say "ni!"'
invalid syntax
'The knights who say "ni!"'
#6: bruce = 6
bruce + 4 = 10
#7: had to write a python program.
def new_line():
print
def three_lines():
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
three_lines()
def clear_screen():
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
clear_screen()
#2: When I move clear_screen() to the top of the program I get: Invalid syntax error.
#3: With me moving new_line() around the program, I got errors saying that new_line() is not defined and Invalid syntax.
Um ill continue this next week, I've learned from the program on #1, is that 1 error can cause everything to mess up no matter how small the error is.
#5:
float
str
'The knights who say "ni!"'
invalid syntax
'The knights who say "ni!"'
#6: bruce = 6
bruce + 4 = 10
#7: had to write a python program.
Chapter 3
#1: (I had a lot of difficulty with this question due to the fact that i instead had def new_lines(): instead of def new_line():. talk about one thing messing your program up).def new_line():
def three_lines():
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
three_lines()
def clear_screen():
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
clear_screen()
#2: When I move clear_screen() to the top of the program I get: Invalid syntax error.
#3: With me moving new_line() around the program, I got errors saying that new_line() is not defined and Invalid syntax.
Um ill continue this next week, I've learned from the program on #1, is that 1 error can cause everything to mess up no matter how small the error is.
Thursday, January 20, 2011
Jan 20
Alright today I'm gonna review the first few chapters that I have done on the How to Think Like a Computer Scientist site, i'll do a quick read through then add my exercises to this.
Chapter 1 Exercises:
#1: print "hello, how are you"
print "Hello, how are you?"
#2: When I add the / into an equation, it causes the equation to divide. Like for example: 2 + 2 will equal 4, but when u substitute + for / you'll get 1 instead of 4. This is caused by the problem changing from a addition problem to a division problem.
#3: more examples of errors are:
2 3 invalid syntax
3***2 invalid syntax
ill stop at two examples because I've come to notice that all the numbers that I apply to python without accurate equation symbols will end in a invalid syntax error.
#4: When I added the " " into print "hello" I got the same results as I did for when I put in print 'hello'. I got hello without any quotation marks.
#5: no question for this one
#6: This one is to make a test1.py file
OK well that wraps up chapter 1.
#2: n = "All work and no play "
p = "makes Jack a dull boy."
n + p = "All work and no play makes Jack a dull boy."
#3: To make 6 * 1 - 2 equal -6 then 4, u add parenthesis where 6*(1-2) so that after 2 is taken from 1 you get -1. Then -1 * 6 will equal -6.
#4: When I add a comma in front of n + P from question #2, I get a syntax error. Python response by saying that the comma is a invalid syntax.
Um due to time, ill continue this next class from question #5.
Chapter 1 Exercises:
#1: print "hello, how are you"
print "Hello, how are you?"
#2: When I add the / into an equation, it causes the equation to divide. Like for example: 2 + 2 will equal 4, but when u substitute + for / you'll get 1 instead of 4. This is caused by the problem changing from a addition problem to a division problem.
#3: more examples of errors are:
2 3 invalid syntax
3***2 invalid syntax
ill stop at two examples because I've come to notice that all the numbers that I apply to python without accurate equation symbols will end in a invalid syntax error.
#4: When I added the " " into print "hello" I got the same results as I did for when I put in print 'hello'. I got hello without any quotation marks.
#5: no question for this one
#6: This one is to make a test1.py file
OK well that wraps up chapter 1.
Chapter 2 Exercises:
#1: When I code: print n = 7, I get a syntax error saying that its a invalid syntax. When I apply print 7 + 5 I get a end result of 12. I also had to print 5.2, "this", 4 - 2, "that", 5/2.0 and got 5.2, this, 2, that, and 2.5. I noticed that even though, without adding quotations to like 7+5 to get 7+5 as a end result instead of getting 12. I could also instead of putting print 7 + 5, I could simply just put in 7 + 5 to get the end result of 12.#2: n = "All work and no play "
p = "makes Jack a dull boy."
n + p = "All work and no play makes Jack a dull boy."
#3: To make 6 * 1 - 2 equal -6 then 4, u add parenthesis where 6*(1-2) so that after 2 is taken from 1 you get -1. Then -1 * 6 will equal -6.
#4: When I add a comma in front of n + P from question #2, I get a syntax error. Python response by saying that the comma is a invalid syntax.
Um due to time, ill continue this next class from question #5.
Subscribe to:
Posts (Atom)