Thursday, June 16, 2011

June 16th

In order to stop the cat from escaping out of the path of the fireball by going off screen I made a total of 6 new boundary sprites lined 3 on each side. This then causes the cat to bounce back after hitting the boundary sprites. I also made the cat just a little bit smaller because with the add fireball, it caused the game to be a little more harder then I wanted. This so far is the game ........

Tuesday, June 14, 2011

June 14th

OK so this is the updated version with the updates that Jeff asked me to make.
Fireball
I changed the death variable to lives and set them to 9 like he did on his remix. I then also added how he changed the cat into its dead costume. I also add another fireball with a different turn time to make it different. I also got the score system up today thanks to this link.

Friday, June 10, 2011

june 10

today i've been studying all over the scratch site looking for how to change the character into a different costume after he dies, im trying to make the cat look dead after the finally life of the cat is gone.

Wednesday, June 8, 2011

june 8

fire ball upgrade
sorry i this is the link verison of what i did today, all i basically did was change where the fireball starts and change the seconds on when it turns.

june 8

http://dl.dropbox.com/u/22931281/fireballgrave.sb

Wednesday, June 1, 2011

June 1st

OK so this is how far I'm at on my program: fireball
from this program, I got help from Anthony as to adding gravity to the cat and having the fireball fly around at random. With the fireball I'm still trying to work out a bug with when you start it, it normally gets stuck to where its just keeps going side to side or up and down. I believe I fixed this problem by changing the value of the degrees from being 15 to 25 to allow for a more dramatic change in direction. I also added a well death count value where after you die 5 times the program ends and just stops. I also changed it to where when you hit the down arrow the cat becomes small and your able to dodge the fireball better. Sense this will be my only post this week,i'll include that next week i'll begin to try to fix the error of the cat being able to go some off the screen to dodge the fireball so that its stuck inside the edge and then i'll also try to transform the cat into an explosion when its hit by the fireball. I'll be hopefully adding a life value and start making a score calculator. Later on I plan on upgrading the look of the fireball so it looks more like a fireball then just a circle with yellow dots on it with a crappy flame on the back. I'll also be later adding a flame sound as the fireball flies from left to right, I don't know if I can make it where it sounds like the flame is going from 1 head phone to the other to allow for a more interactive effect to the game.

Monday, May 23, 2011

May 23

Today I was trying to work on making a smiley just randomly flash but also run around the screen until the scratch cat touched it and it then disappears.
OK so instead of using a smiley I just decided to put in a fireball(crappy looking but its a fireball) to randomly fly around the screen but I'm trying to perfect it as to it will randomly fly around and just change direction when it hits the edges of the screen.  
This is what i have so far, it looks crappy but I'm still working on it

Thursday, May 19, 2011

also due to drop box issues I couldn't post my edit as to what i was working on with that game/program. i plan on hopefully being able to show it tomorrow.

May 19th

ok so today I was studying the following scratch game:
spiral circle
from this program, as in tomorrow, i plan on upgrade the color effects and the shape to change from only being a circle to being a square then a triangle then back to a circle. 

Monday, May 9, 2011

May 9

Scratch account
i got fixed on the bacteria game which i wanna try.
which i guess you basically just have a multiple sequence going on.

Friday, April 15, 2011

April 15

Well sense it didn't post my blog yesterday ill repeat what I put up yesterday.
Possible Backgrounds:
Fire
Space
Falling Computer Code
Fantasy City
Moon With Earth
Distant World
Space With Planets
City
With the above backgrounds, I can then use them to change the duck hunting game to multiple games such as: space defenders, city defenders, etc
From the sushi program, I haven't had the time to code it yet but I'm gonna use one of the above backgrounds by following how you had to input the background image.This then will allow me to have one of the above images as my background. From there ill use elements from the pong game 2 allow me 2 make a shooter(spot) and then use the random event to make the enemies to appear randomly.
I may just make the main spot where your shooting just ether a cross hair or a simple triangle. Or just reverse that towards the enemies as of them being some random shape.

Wednesday, April 13, 2011

April 13

Ok what I want to recreate this quarter is the original duck hunting game like some1 did off of the pygame web site.
Duck Hunting Game
From this game I wanna change the effects of the game, like after you reach a certain number of kills the birds get faster or they change into a different thing for you to shoot. Or also allow for a upgrade in weapons as you go through the levels to allow for better chances of hitting the faster more smart ducks.

Tuesday, April 5, 2011

April 5

Below Resources:
How to Think Like a Computer Scientist Website

Graphics API for Students of Python: GASP


I also have the Beginning Game Development with Python and Pygame book
Game I wanna base my game off of

From both of these resources, I've noticed that I may have to change from being a first person shooter to a third person shooter. Or just like the game I've provided in the resources i could base the game off of a single character being housed in the middle of the game with multiple enemies attacking on both sides and as the game progresses, allow for upgrades. Basically demonstrated in the game. Off of the How to Think Like a Computer Scientist website, I've found off of appendix b the origination of the shapes that I can use to build the character and enemies.

After playing a few rounds on the game I believe this will be sorta easy, its sorta just like the pong game but instead of ending after u get a certain amount of point, it gets harder. I can use the collision event that happens in the pong game to then input an explosion from the object hitting it. Thus allowing the appears of the enemy getting destroyed.

So far, I haven't found any tutorials in/on any of my resources. So this is gonna be a bit tricky on figuring how i'll be able to complete this game.

Monday, April 4, 2011

April 4

The name of my program will be called "A Better Game"

My goal for this final quarter is to produce a game that is basically a basic first person shooter. The game may only be a level or two, but I just wanna have the concept of it being a first person shooter.

Ill continue on rest of goal setting tomorrow

Thursday, March 31, 2011

Mar 31

Starting todays with lists are mutable:
list are mutable program and example
This is a very easy concept to understand because really I this sorta when I was working with List Operators from my previous post. Basically how the list are mutable when you had to add 2 and 4 from my example in the above program, you basically did the same thing I did for list operators just all in this is that you inputed the numbers between multiple numbers instead of just putting them at the end or at the beginning.
List deletion:
list deletion program
Well really this method is pretty easy to understand due to all you have to do is put in a input to delete something within the list. Which from the program, del is asking you to do is delete the variable that is one in the list. Which happens to be two.
Objects and Values:
Objects and values program
When the objects and values you are listing aren't in a list then like from the program above you'd true for both a == b and a is b because they are equal. On the other hand you get false for a is b and you get true a == b because a == b is that a and b equal but for a is b, they aren't the same. They are two distinct lists of their own.
Aliasing:
aliasing program 
This program  basically says that variable a equals [1, 2, 3] and then variable b equals variable a so there for they are the same. When you input b[0] = 5, its changing what variable a = into [5, 2, 3]. This is because like I said, variable a and b are the same.
Cloning:
Cloning program
Frankly people believe cloning is pretty hard even though I believe this is pretty easy. Really the clone of this program is both b and d. This is due to the fact that they follow everything that a and c tell them to do because they equal what a and c [:] equals. So you can put as much as you want for b or d to change a and c, but they will always come out with their original values but will only change when assigned to a new value. 

Tuesday, March 29, 2011

Contiue onwards onto March 29th

This is me continuing on chapter 9 with list length:
List length program with example.

When it comes to list membership its very easy to understand. Like:
list membership 
From the program that ask that if pestilence was in horsemen, which it is outlined to be inside horsemen. Then it asks if debauchery was in horsemen which would obviously come out to false. To get this program to come out to be true you would have to say : 'debauchery' not in horsemen. This then comes out to being true.
list membership update with examples.
Onto to list operators:
list operator program
In list operators, its fairly easy to understand that withing the [] you can basically add anything to it. Basically all you have to do is just assign a variable to the numbers/ letters in the [], just with the letter you need [' '] with the word/ letters being insides the ' ' between them. But as you seen from my program I experiment with making the variables by trying to get them to equal the other variables outcomes. By for example:
g = f + c
then getting i to = g + a thus getting the following outcome:
['eye', 'i', 1, 2, 3, 4, 5, 6, 1, 2, 3]
Me assigning i to equal the outcomes of the other variables allowed me to get a even bigger outcome then just assigning i to equal just 2 of the other variables. I basically just wanted to make the outcome of this to be more complex.
List slices aren't to difficult ether, their just mixing slicing and list into one program:
list slice with original program and example.
Range is easy to understand:
range
I only had difficulties on range when it was coming to understand the negative step size:
examples
I don't get this because there is 3 numbers and I no that the start much be higher then the stop but I don't know what the middle number is suppose to mean.

Friday, March 25, 2011

Mar. 25

I really didn't get to finish the game I was trying to create. When working on it, I got stuck on the part when I had to change distance to hit and then put in the code and make it pass the doctest. Every time I tried i always got 2 out of 4 fail. I really didn't know that making a game would have been this difficult.

def hit(bx, by, r, px, py, h):
"""
>>> hit(760, 100, 10, 780, 100, 100)
False
>>> hit(770, 100, 10, 780, 100, 100)
True
>>> hit(770, 200, 10, 780, 100, 100)
True
>>> hit(770, 210, 10, 780, 100, 100)
False
"""
The above was what I had to make pass the doctest. From my program that I'll be adding as the last part of todays blog message, I had put return (h <= by) and (bx <= r) and had to fit somewhere into the program that it would return true. Also with (h <=by) I had to make sure it told that the ball was between the bottom and the top of the paddle, and then for (bx <= r) I had to make sure that the horizontal location of the ball is less than or equal to the radius away from the front of the paddle.
http://dl.dropbox.com/u/24004516/pong2.py
The above link is my program.
So as Mr. Elkner said, come Monday hes gonna help me with this program. Also my homework for the weekend is to get a notebook for Monday.

Wednesday, March 23, 2011

Mar. 23

http://dl.dropbox.com/u/24004516/catch.py
The above link turns the circle thats acting as a mitt into a square, I'm thinking bout changing the dimensions more on the square cause it seems a bit small.

Tuesday, March 22, 2011

Mar. 22

http://dl.dropbox.com/u/24004516/scores.py
The above link is my continue onto the pitch game.
http://dl.dropbox.com/u/24004516/catch.py
The above link shows that the computer wins no matter what, even if you catch the ball. Whats weird is it tells me too add:
Text("Computer Wins!", (340, 290), size=32)
sleep(2)
after:
if ball_ x > 810:
But every time I moved the text up after if ball_x, it always came up as an error. The error was:
IndentationError: expected an indented block
http://dl.dropbox.com/u/24004516/catch.py
The above is the fixed version of catch. I was finally able to figure out that the IndentationError was because I didn't indent both Text... and sleep(2).
http://dl.dropbox.com/u/24004516/catch.py
The above program is the finished catch.py program. After finishing the program the first time, it ended up not working. After finding a few errors I was able to make the program to work thus showing ether player as the winner or computer as the winner after getting 5 points.

Friday, March 18, 2011

Mar 18

from gasp import *

number = random_between(1, 1000)
guesses = 1
guess = input("Guess the number between 1 and 1000: ")

while guess != number:
if guess > number:
print "Too high!"
else:
print "Too low!"
guess = input("Guess the number between 1 and 1000: ")
guess += 1

print "\n\nCongratulations, you get it in %d guesses!\n\n" % guesses
When I inputed the above program i had to guess a few times in order to find the number that was randomly picked, which i got 719 as my number between 1 - 1000. 
from gasp import *

number = random_between(1, 1000)
guesses = 0

while True:
guess = input("Guess the number between 1 and 1000: ")
guesses += 1
if guess > number:
print "Too high!"
elif guess < number:
print "Too low!"
else:
print "\n\nCongratulations, you got it in %d guesses!\n\n" % guesses
break
This is an update of the first program that will give the accurate results of how many guesses it took you to guess the right number. This I say is a very cool program cause it functions as a person as to picking a random number and asking you to find the right number and pops out the amount of times you had too guess in order to get the right number. 
from gasp import *

def distance(x1, y1, x2, y2):
return ((x2 - x1)**2 + (y2 - y1)**2)**0.5
begin_graphics(800, 600, title="Catch", background=color.RED)
set_speed(120)

ball1_x = 10
ball1_y = 300
ball1 = Circle((ball1_x, ball1_y), 10, filled=True)
ball1_dx = 4

ball2_x = 790
ball2_y = 300
ball2 = Circle((ball2_x, ball2_y), 10)
ball2_dx = -4

while ball1_x < 810:
ball1_x += ball1_dx
ball2_x += ball2_dx
move_to(ball1, (ball1_x, ball1_y))
move_to(ball2, (ball2_x, ball2_y))
if distance(ball1_x, ball1_y, ball2_x, ball2_y) <= 20:
remove_from_screen(ball1)
remove_from_screen(ball2)
break
update_when('next_tick')
sleep(1)
end_graphics()
The game being created from this program I'm starting to see is starting to get more and more complicated. This simple game is pretty easy to understand. 
from gasp import *

def distance(x1, y1, x2, y2):
return((x2 - x1)**2 + (y2 - y1)**2)**0.5
begin_graphics(800, 600, title="Catch", background=color.RED)
set_speed(120)

ball_x = 10
ball_y = 300
ball = Circle((ball_x, ball_y), 10, filled=True)
dx = 4
dy = random_between(-4, 4)

mitt_x = 780
mitt_y = 300
mitt = Circle((mitt_x, mitt_y), 20)

while True:
# move the ball
if ball_y >= 590 or ball_y <= 10:
dy *= -1
ball_x += dx
if ball_x > 810:     # the ball has gone off the screen
break
ball_y += dy
move_to(ball, (ball_x, ball_y))
# check on the mitt
if key_pressed('k') and mitt_y <= 580:
mitt_y += 5
elif key_pressed('j') and mitt_y >= 20:
mitt_y -= 5
if key_pressed('escape'):
break 
move_to(mitt, (mitt_x, mitt_y))
if distance(ball_x, ball_y, mitt_x, mitt_y) <= 30:   # ball is caught
remove_from_screen(ball)
break 
update_when('next_tick')
end_graphics()
When running the above program, I got the following error:
Exception in thread QueueFeederThread (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
  File "/usr/lib/python2.6/threading.py", line 484, in run
  File "/usr/lib/python2.6/multiprocessing/queues.py", line 242, in _feed <class 'cPickle.PicklingError'>: Can't pickle gasp.api.Circle: import of module gasp.api failed
I believe this is a error off of gasp but I can't tell. 

Thursday, March 17, 2011

Mar. 17

fruit = 'rampage'
"""
>>> type(fruit)
<type 'str'>
>>> len(fruit)
7
>>> fruit[:3]
'ram'
"""

if __name__ == '__main__':
import doctest
doctest.testmod()
This program I had to do to make it pass the doctest.
from gasp import *

begin_graphics(800, 600, title="Catch", background=color.YELLOW)
set_speed(120)

ball_x = 10
ball_y = 300
ball = Circle((ball_x, ball_y), 10, filled=True)
dx = 4
dy = 1

while ball_x < 810:
ball_x += dx
ball_y += dy
move_to(ball, (ball_x, ball_y))
update_when('next_tick')

end_graphics()
The above program makes a ball appear then fly across the screen until it hits the side of the window and disappears. The background also to this graphic is then yellow. I can manipulate the color of the background by just changing the color, I can also change the speed of the ball flying across the screen.
>>> from gasp import *
>>> i = 0
>>> while i < 10:
...     print random_between(-5, 5)
...     i += 1
... 
5
2
-4
5
-5
-5
4
-5
4
-1
The above program is called a more or less random integer. This program will random choose 10 numbers between -5 and 5, so really your results to this program varies. 
from gasp import *

begin_graphics(800, 600, title="Catch", background=color.RED)
set_speed(120)

ball_x = 10
ball_y = 300
ball = Circle((ball_x, ball_y), 10, filled=True)
dx = 4
dy = random_between(-4, 4)

while ball_x < 810:
ball_x += dx
ball_y += dy
move_to(ball, (ball_x, ball_y))
update_when('next_tick')

end_graphics()
The above program has been modified to appear with a background of red and then I changed the dy = 1 to dy = random_between(-4, 4) which will cause a random number to be chosen to be used for the direction of the ball

Wednesday, March 16, 2011

Mar. 16

This program is easy to understand:

>>> i = 1
>>> print "i\ti**2\ti**3\ti**5\ti**10\ti**20"
i i**2 i**3 i**5 i**10 i**20
>>> while i <= 10:
...     print i, '\t', i**2, '\t', i**3, '\t', i**5, '\t', i**10, '\t', i**20
...     i += 1
...
1 1 1 1 1 1
2 4 8 32 1024 1048576
3 9 27 243 59049 3486784401
4 16 64 1024 1048576 1099511627776
5 25 125 3125 9765625 95367431640625
6 36 216 7776 60466176 3656158440062976
7 49 343 16807 282475249 79792266297612001
8 64 512 32768 1073741824 1152921504606846976
9 81 729 59049 3486784401 12157665459056928801
10 100 1000 100000 10000000000 100000000000000000000
Well from the program it tells the out put to be put into a table('\t'). From this then it puts the equation into the correct line. 
>>> i = 1
>>> print "%-4s%-5s%-^s%-*s%-13s%-15s" % \
...     ('i', 'i**2', 'i**3', 'i**5', 'i**10', 'i**20')
>>> while i <= 10:
...     print "%-4d%-5d%-6d%-8d%-13d%-15d%" % (i, i**2, i**3, i**5, i**10, i**20)
...     i += 1
... 
i    i**2   i**3   i**5   i**10    i**20
1   1    1     1       1            1              
2   4    8     32      1024         1048576        
3   9    27    243     59049        3486784401     
4   16   64    1024    1048576      1099511627776  
5   25   125   3125    9765625      95367431640625 
6   36   216   7776    60466176     3656158440062976
7   49   343   16807   282475249    79792266297612001
8   64   512   32768   1073741824   1152921504606846976
9   81   729   59049   3486784401   12157665459056928801
10  100  1000  100000  10000000000  100000000000000000000
The change on this program is that it outputted with i, i**2, i**3, i**5, i**10, and i**20
>>> 'Python'[1]
'y'
>>> "Strings are sequences of characters."[5]
'g'
>>> len("wonderful")
9
>>> 'Mystery'[:4]
'Myst'
>>> 'p' in 'Pinapple'
True
>>> 'apple' in 'Pinapple'
True
>>> 'pear' in 'Pinapple'
False
>>> 'apple' > 'pinapple'
False
>>> 'pinapple' < 'Peach'
False
(This was me recapping on stuff i did during chapter.)

Friday, March 11, 2011

Mar. 11

>>> import string
>>> string.find("bob", "b", 1, 2)
-1
With this input off of the string module, I was confused as to how did the program get an output of -1. I'm just confused with that part of the program
>>> '2**10 = 1024 and 4 * 5 = 20.000000'
'2**10 = 1024 and 4 * 5 = 20.000000'
>>> "His name is %s." % "Arthur"
'His name is Arthur.'
>>> name = "Alice"
>>> age = 10
>>> "I am %s and I am %d years old." % (name, age)
'I am Alice and I am 10 years old.'
>>> n1 = 4
>>> n2 = 5
>>> "2**10 = %d and %d * %d =  %f" % (2**10, n1, n2, n1 * n2)
'2**10 = 1024 and 4 * 5 =  20.000000'
With the % input, you can have it stand for different things such as from the program the first %s = name and then the second %d = age..

Thursday, March 10, 2011

Mar. 10

When working with the string module, I realized that the expression dir means directory.
>>>import string
>>>dir(string)

['Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
The above is the full list of the items in the string module.
When i ask to see all the digits I get from the string module I get:
>>> print string.digits
0123456789
Not surprising you get all the digits. 
>>> string.find("banana", "na")
2
The out come of this program is 2 because in the word "banana", you will find 2 occurrence of "na". >>> >>>print string.lowercase
abcdefghijklmnopqrstuvwxyz
>>> print string.uppercase
ABCDEFGHIJKLMNOPQRSTUVWXYZ
>>> print string.digits
0123456789
When working with the string module, I've noticed that it has many possible outputs to the program. Basically this program has self explanatory, such as lowercase, uppercase, and digits. 
>>> print string.whitespace
When you put this into the terminal you get just a few open lines of blank space.

Wednesday, March 9, 2011

Mar. 9

Working with the in command, I've noticed that it basically tells what it does. For example:

>>> 'p' in 'apple'
True
>>>
>>> 'i' in 'apple'
False
>>> 'ap' in 'apple'
True
>>> 'pa' in 'apple'
False
This program will only come out to saying its True only if the letter your asking for is inside the word you plug in. Like for apple, you already know you'd find a-p-p-l-e in the word. So if you ask the program if q or like if w is in the word, it will come out False.
>>>'apple' in 'apple'
True
You get this because well you'd find apple when you look in the word apple. This is basically self explanatory. 
>>> def remove_vowels(s):
...     vowels = "aeiouAEIOU"
...     s_without_vowels = ""
...     for letter in s:
...             if letter not in vowels:
...                     s_without_vowels += letter
...     return s_without_vowels
... 
With this program, you must first assign a word to a variable.
a = 'apple'
Once you have the variable you just plug the variable into the program and get:
'ppl'
So the program basically just deletes all the vowels in the word and just spits out what ever is left. 
>>> fruit = "banana"
>>> count = 0
>>> for char in fruit:
...     if char == 'a':
...             count += 1
...     print count
... 
0
1
1
2
2
3
This program just outputs how many times you input 'a'. So as the program inputs 'banana' into its system, it starts with b which is 0, then the a which now is 1, then the n which stays as one saying thats there has been an a before. Then another a which now is 2. Then another n which will stay 2 as previously stated. Then the 3rd and final a which is now called 3, thus getting the above results. 

Tuesday, March 8, 2011

Mar. 8

To re-enforce what I've learned on string slices. An example to help me out is:
>>>s = "Andrew"
>>>print s[:]
Andrew
>>>print s[1:2]
n
>>>print s[1:5]
ndre
>>>print s[:-1]
Andre
>>>print s[-1:]
w
And so on......
This technique is really easy to understand. I just had to keep in mind the basic principle that instead of starting to count at one, you start at zero.
With immutable strings, the following program is easy to understand.

>>> greeting = "Hello, world!"
>>> newGreeting = 'J' + greeting[1:]
>>> print newGreeting
Jello, world!
When you want to change the out put of "Hello, world!" to "Jello, world!" all you'd do like the program shows is put new before your variable, then in order to change the letter of the text you'd have to put the exact point to change. Like it says to change from greeting change it would print everything after the first letter, which is H. The [1:] would print every other letter after the H, so then when  you add the 'J' you get the output of "Jello, world!" But if i first started out with trying to change the first word on in greeting by just asking for greeting[0] = 'J' then id get the error of : TypeError: 'str' object does not support item assignment.

Friday, March 4, 2011

Mar. 4

Starting on chapter 7 with compound data types. 
When I put into the terminal:
>>> fruit = "banana" 
>>> letter = fruit[1]
>>> print letter 
I would get a, I really expected to get like f or b but reading on I was able to find out that with computer programing, you start off by counting at 0. So instead, if i used fruit[0] then id get b instead of a. I then after realizing that it would print a, that instead of printing letters from fruit, it would print from banana, which I should have realized when I first put in fruit = "banana". 
Here area all the letters and the fruit[n] you can use in order to finish typing out banana:
fruit[0]
b
fruit[1]
a
fruit[2]
n
fruit[3]
a
fruit[4]
n
fruit[5]
a
The next step to chapter 7 was length, which the abbreviation for length on python is len. 
>>>fruit = "banana"
>>>len(fruit)
so for this program, length would be used as to tell how many letters long the word was. You would get an output of 6 for this program. 
example:
Instead of using fruit, I used word for this program. 
>>> word = "pneumonoultramicroscopicsilicovolcanoconiosis"
>>> len(word)
45
The word used was the longest word that can be found in a major dictionary. This word as the program exclaims has 45 letters/ length of the word is 45 characters. 
In order to get the program to say the letter from the end of the word you would put in(this is back with the banana program:
>>> length = len(fruit)
>>> last = fruit[length-1]
>>>last
'a'
Then if you change fruit[length-1] to fruit[length-2] you would get 'n' and so on and so forth. 
A transversal program like the following puts on its own line a letter of "banana":
 index = 0
>>> while index < len(fruit):
...     letter = fruit[index]
...     print letter
...     index += 1
... 
b
a
n
a
n
a
You can also get the same results using:
>>> for char in fruit:
...     print char
... 
b
a
n
a
n
a
The following program is used to assign the prefix with the suffix of a word and have them in alphabetic order:
 >>> prefixes = "JKLMNOPQ"
>>> suffix = "ack"
>>> 
>>> for letter in prefixes:
...     print letter + suffix
... 
Jack
Kack
Lack
Mack
Nack
Oack
Pack
Qack
>>> 
Even though Oach and Qack are missed spelled do to they having more letters in the word. Correction is Ouack and Quack
Working with a program that produces just the letters out of a word, I've used the [:] code:
>>> fruit = "banana"
>>> fruit[:3]
'ban'
>>> fruit[3:]
'ana'
When using the [:], this allows me to choose which letters I want displayed. For instance from the program above I used fruit[:3] to get the first 3 letters of "banana", and then used fruit[3:] for the last 3. Basically the side the number is on depends on what it will display but one side must be blank to show the numbers you want to display instead of setting a guide to another area to stop at(I don't know if I'm explaining this clearly, please comment if it makes sense to you, if not I'll update this when I get feedback.). 

Thursday, March 3, 2011

This is a rewritten sequence program:
>>> def sequence(n):
...     while n != 1:
...             print n, 
...             if n % 2 == 0:
...                     n = n / 2
...             else:
...                     n = n * 3 + 1
... 
>>> sequence(3)
3 10 5 16 8 4 2
The program above also so the program working. 
This is the num_digits program that I've failed to put on here. This program also has three examples of the program working and getting an output.
>>> def num_digits(n):
...     count = 0
...     while n:
...             count = count + 1
...             n = n / 10
...     return count
... 
>>> num_digits(710)
3
>>> num_digits(999999999999999)
15
>>> num_digits(111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111)
96
>>> 
This program is basically self explanatory, it basically just counts the number places in the number. 
This is the num_zero_and_five_digits. This program counts the number of zeros and number of fives in the number:
>>> def num_zero_and_five_digits(n):
...     count = 0
...     while n:
...             digit = n % 10
...             if digit == 0 or digit == 5:
...                     count = count + 1
...             n = n / 10
...     return count
... 
>>> num_zero_and_five_digits(1055030250)
7

Wednesday, March 2, 2011

Mar. 2

Sorry I messed up on writing Newton's algorithm, the program is:

>>> def sqrt(n):
...     approx = n/2.0
...     better = (approx + n/approx)/2.0
...     while better != approx:
...         approx = better
...         better = (approx + n/approx)/2.0
...     return approx
...
These are the questions for chapter 6


Tuesday, March 1, 2011

Mar. 1

This program is basically a program that shows ab = ba as a table.

def print_multples(n):
i = 1
while i <= 6:
print n * i, '\t',
i += 1
print
def print_mult_table(high):
    i = 1
    while i <= high:
        print_multiples(i)
        i += 1
So for example, if we plug in print_mult_table(7) we get the following table:
1   2   3   4   5   6   7
2   4   6   8   10   12  14
3   9   12  15  18  21
4   8   12   16  20  24  28
5   10   15   20   25   30   35
6   8   12  18   24   30   36   42
7   14   21   28   35  42  49
(sorry this time i didn't try to equal up the sides of the table)
This program makes it where the table will have a downwards slope as the number rises. This table also takes away the numbers 2-7 from the top row, then each row it adds another number. Here is the table so you understand what I mean:

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
I then started to work on Newton's method which the program was:
def sqrt(n): approx = n/2.0 better = (approx + n/approx)/2.0 while better != approx: approx = better better = (approx + n/approx)/2.0 return approx
I then plugged in sqrt(25) and got an out-put of 5.0:
>>> sqrt(25) 5.0

Monday, February 28, 2011

Feb 28

Recapping from last week, when i tried to to re-put in the program for print_multiples. I then made an error but when I enter the program I got no error message, so what I did from there was put into the python terminal was print_multiples(3). After I did this, surprisingly I didn't get a error message, I got a continuously flowing 3 table. The program again was:
 def print_multiples(n):
...     i = 1
...     while i <= 6:
...             print m * i, '\t',
...             i += 1
...     print
...
>>>

My modified program of this program was:
>>> def print_multples(n):
...     i = 1
...     while i <= 6:
...             print n * i, '\t',
...     i += 1
... 
>>> 

The error was where i += 1 was suppose to be found right under print n * i, '\t', but instead I missed typed. I tried figuring out a way to allow this program to stop generating the number 3 but so far I've been unable to find a way to get the program to stop the generation. 
def print_mult_table():
i = 1
while i <= 6:
print_multiples(i)
i += 1

The book told me to wrap this program into the program I first created. So the overall program is:
def print_mult_table():
i = 1
while i <= 6:
print_multiples(i)
i += 1
def print_multiples(n):
i = 1
while i <= 6:
print n * i, '\t', 
i += 1
i = 1
while i <= 6:
print_multiples(i)
i += 1

After I applied this program to the terminal I got:
File "print_multiples.py", line 13, in print_multiples
    print_multiples(i)

I got this error a good 50 times in the terminal. I really don't get what the results of this program means. I really don't know if this program has a error or that the program is suppose to out put File "print_multiples.py", line 13, in print_multiples
   print_multiples(i)


Friday, February 25, 2011

Feb 25

So starting with tables, they seem easy pretty easy to understand, well at least the one I've tired. The program is:
x = 1
while x < 13:
        print x, '\t\' , 2**x
       x += 1
This program is basically having calling x to count up to 1-12 on one side of the table('\t\' is keyed together with table). Then on the right side the number starts from 2 then doubles, then doubles, then a that number doubles and so on and so forth.
Then working with the two dimensional table program:

i = 1
>>> while i <= 6:
...     print 2 * i, '  ',
...     i += 1
... print
You get an outcome of the number just counting up by 2s starting with 2 and counting on. Also with this program it tells the number to be spaced 3 times after it is outputted on the table, for example:
2   4   6    8   10   12   14   16   18   20.... and so on.
def print_multiples(n):
...     i = 1
...     while i <= 6:
...             print n * i, '\t\', 
...             i += 1
...     print
When you plug 2 into this program you get:
3   6   9  12  15  18... and so on.
But then when you change the 2 to 4 you get an outcome of:
4   8   12   16   20....and so on. 
The next program combines a few tables to produce a big table:def print_multiples(n):
i = 1
while i <= 6:
print n * i, '\t', 
i += 1
i = 1
while i <= 6:
print_multiples(i)
i += 1
With an outcome of: (sorry took some numbers out so that table look a little equal, side wise) 
1   2   3   4   5   6
2   4   6   8   10  12
3   6   9   12  15  18
4   8   12  16   20
5   10   15   20   25
6   12   18   24   30


Thursday, February 24, 2011

Feb 24

When working with the digit program. I began to think, what if I add more digit space; would it still give me the number of digits in the number. Testing the program:
def num_digits(n):
        count = 0
        while n:
                 count = count + 1
                 n = n /  10
        return count
I then plugged in 9,999,999,999,999,999,999,999. After i enter this number into the program, it correctly came out to have 22 digits.
With working with abbreviation of the numbers i found it really easy to understand that += mean + what ever number. The abbreviation also works with all the other symbols in mathematical expressions such as * / and -. Lets me show you how all the expressions will look. Starting with that count = 0
count = 0
count += 1
count = 1

count = 0
count -= 1
count = -1

count = 0
count += 2
count = 2
count  /= 2
count = 1

count = 0
count *= 1
count = 0

count = 3
count %= 2
count = 1
These are all the expressions you can use.

Tuesday, February 22, 2011

Feb 22

This is the fixed hypotenuse program:

def hypotenuse(a, b):
"""
>>> hypotenuse(3, 4)
5.0
>>> hypotenuse(12, 5)
13.0
>>> hypotenuse(7, 24)
25.0
>>> hypotenuse(9, 12)
15.0

"""
return ((a**2) + (b**2))**0.5

if __name__== '__main__':
import doctest
doctest.testmod()

Friday, February 18, 2011

Feb 17- 18

This is a fix on the factor program:

def is_factor(f, n):
"""
>>> is_factor(3, 12)
True
>>> is_factor(5, 12)
False
>>> is_factor(7, 14)
True
>>> is_factor(2, 14)
True
>>> is_factor(7, 15)
False
"""
return n % f == 0
if __name__ == '__main__':
import doctest
doctest.testmod()

This is a fix on the is divisible by 2 or 5 program:
def is_divisible_by_2_or_5(n):
    """
      >>> is_divisible_by_2_or_5(8)
      True
      >>> is_divisible_by_2_or_5(7)
      False
      >>> is_divisible_by_2_or_5(5)
      True
      >>> is_divisible_by_2_or_5(9)
      False
    """
    return n % 2 == 0 or n % 5 == 0

if __name__ == '__main__':
    import doctest
    doctest.testmod()

This is a fix on the multiple program:
def is_multiple(m, n):
    """
      >>> is_multiple(12, 3)
      True
      >>> is_multiple(12, 4)
      True
      >>> is_multiple(12, 5)
      False
      >>> is_multiple(12, 6)
      True
      >>> is_multiple(12, 7)
      False
    """
    return m % n == 0
if __name__== '__main__':
import doctest
doctest.testmod()

Chp 6:
When starting out using multiple assignments, I noticed that when you first put in a number like lets say a = 3 and then u change it to where a = 4. When you tell python to print a you'll get 4 instead of 3 because sense you changed a value to being 4 last, that would be the output of the number. Also when you try to assign the variable a number you must always have the variable going first before the number. Ex: a = 7 correct, 7 = a incorrect. When you put 7 = a, that is illegal meaning it will not work. 
On updating variables, I've found out that when you first put a variable in like x = 99 then if u want to improve the variable to where its a different number you can just do x = a different number but you can also use x = x -/+* a number(you can use all equation symbols). So lets say I wanted to change x = 99 to x = 100, so what I would do is ether do x = 100 or i can do x = x + 1. After putting the second x = x + 1 and you say print x, you'll get 100. 
Using the countdown program helped me understand that when you use a variable like n and then put n > 0:   print n then n = n - 1. When you put n = n -1 and n > 0, this basically will continue a count down until it hits 0 then will print or do what ever you tell it to print.  

Wednesday, February 16, 2011

Feb 16

This is the fix program of ch05 program:

def compare(a, b):
"""
>>> compare(5, 4)
1
>>> compare(7, 7)
0
>>> compare(2, 3)
-1
>>> compare(2, 1)
1
"""
return a-b

if __name__ == '__main__':
import doctest
doctest.testmod()

this will now pass the doctest
Fix on the hypotenuse program

def hypotenuse(a, b):
"""
>>> hypotenuse(3, 4)
5.0
>>> hypotenuse(12, 5)
13.0
>>> hypotenuse(7, 24)
25.0
>>> hypotenuse(9, 12)
15.0
"""
return

if __name__== '__main__':
import doctest
doctest.testmod()
This is not the completed program yet, im still working on fixing the return so that the program passes the doctest. So far I no that the number needs to have .0 in it to allow the results to have .0 to them. I've ruled out that a**2 + b**2 will not work. I've also tried a - b + 4 which also came out to fail.

Tuesday, February 15, 2011

Feb 14-15

Fix on #4:

def is_even(n):
"""
>>> is_even(1)
False
>>> is_even(2)
True
>>> is_even(3)
False
>>> is_even(4)
True
>>> is_even(5)
False
>>> is_even(6)
True
>>> is_even(7)
False
>>> is_even(8)
True
>>> is_even(9)
False
"""
return n % 2 == 0
if __name__== '__main__':
import doctest
doctest.testmod()

and which now will allow for the program to run and pass. 
Fix on #5:
def is_odd(n):
"""
>>> is_odd(1)
True
>>> is_odd(2)
False
>>> is_odd(3)
True
>>> is_odd(100)
False
>>> is_odd(9999)
True
>>> is_odd(1000000)
False
>>> is_odd(300957)
True
>>> is_odd(298745230)
False
"""
return not n % 2 == 0
if __name__== '__main__':
import doctest
doctest.testmod()
This then allows the program to change from having to check to see if the number is even to check to see if the number is odd. What I had to change from the is_even program was the return n % 2 == 0 to return not n % 2 == 0. Which this is meaning that if the number(n) is divisible by 2 and has nothing left over, it is not a odd number, but sense for the is_odd program I applied not to the body to tell that if the numbers do not fight the divisible property of 2 = 0 then it will be a odd number. 
There was not to much put on for these too days due to I was trying to figure out what I had to do to change the output of the is_even program so that it outputs the right figures for is_odd program.

Friday, February 11, 2011

Feb 11

OK when working on questions #4 and #5, I've been having some difficulty with it. What I'm suppose 2 do is for question #4 is make a program that determines if a number is even and if it is even then it will out put True. If the number is an odd number then the out put would come out to be False. Then see for question #5 I have to do the same thing but instead for only odd numbers. Ill continue on this program and see how far I can get.
So far this hasn't given me any problem or said that the test has failed for question #4 so this is the program:

def is_even(n):
"""
>>> is_even(1)
False
>>> is_even(2)
True
>>> is_even(3)
False
>>> is_even(4)
True
>>> is_even(5)
False
>>> is_even(6)
True
>>> is_even(7)
False
>>> is_even(8)
True
>>> is_even(9)
False
"""
if __name__== ' __main__':
import doctest
doctest.testmod()

#5: def is_odd(n):
"""
>>> is_even(1)
True
>>> is_even(2)
False
>>> is_even(3)
True

>>> is_even(4)
False

>>> is_even(5)
True

>>> is_even(6)
False

>>> is_even(7)
True

>>> is_even(8)
False

>>> is_even(9)
True

"""
if __name__== ' __main__':
import doctest
doctest.testmod()
#6:

Thursday, February 10, 2011

Feb 10

********************************************************************************
File "intercept.py", line 5, in __main__.intercept
Failed example
      intercept(6, 1, 1, 6)
Expected:
      7.0
Got nothing
*******************************************************************************
File "intercept.py", line 7, in __main__.intercept
Failed example:
      intercept(4, 6, 12, 8)
Expected:
       5.0
Got nothing
*******************************************************************************
1 items had failures:
     3 of     3 in __main__.intercept
***Test Failed*** 3 failures.
#4:

Wednesday, February 9, 2011

Feb 7-9

Alright on Monday I wasn't able to get on due to computer issues. This continued to at least half of the class on Tuesday. So today i'll continue on Chapter 5 questions #1.
#1: def compare(a, b)
"""
>>> compare(5, 4)
1
>>> compare(7, 7)
0
>>> compare(2, 3)
-1
>>> compare(42, 1)
1
"""


"""
>>>compare(a > b)
1
>>>compare(a == b)
0
>>>compare(a < b)
-1
"""


if __name__== ' __main__':
import doctest
doctest.testmod()
This program really got me for awhile. When I first started out I had changed the def compare(a, b) to def compare( a > b). Which was giving me an error saying that > was an invalid syntax. But the spur of the moment thought make me think to instead add a > b, a == b, and a < b, to next to the >>>compare. After one try i got this right away. This was a pretty easy program to make after I found out exactly what I had to do.
#2: def hypotenuse(a, b): """ >>> hypotenuse(3, 4) 5.0 >>> hypotenuse(12, 5) 13.0 >>> hypotenuse(7, 24) 25.0 >>> hypotenuse(9, 12) 15.0 """ if __name__== '__main__': import doctest doctest.testmod()
Which I then got an output of:

*****************************************************************************
File "hypotenuse.py", line 7, in __main__.hypotenuse
Failed example:
hypotenuse(7, 24)
Expected:
25.0
Got nothing
*****************************************************************************
File "hypotenuse.py", line 9, in __main__.hypotenuse
Failed example:
hypotenuse(9, 12)
Expected:
15.0
Got nothing
*****************************************************************************
1 items had failures:
4 of 4 in __ main__.hypotenuse
***Test Failed*** 4 failures.
#3: def slope(x1, y1, x2, y2): """ >>> slope(5, 3, 4, 2) 1.0 >>> slope(1, 2, 3, 2) 0.0 >>> slope(1, 2, 3, 3) 0.5 >>> slope(2, 4, 1, 2) 2.0 """ if __name__== '__main__': import doctest doctest.testmod()
 
With an end result of:
*****************************************************************************
File "slope.py", line 7, in __main__.slope
Failed example:
      slope(1, 2, 3, 3)
Expected:
      0.5
Got nothing
*****************************************************************************
File "slope.py", line 9, in __main__.slope
Failed example:
      slope(2, 4, 1, 2)
Expected:
       2.0
Got nothing
*****************************************************************************
1 items had failures:
    4 of      4 in __main__.slope
***Test Failed*** 4 failures.
ef intercept(x1, y1, x2, y2):
    """
      >>> intercept(1, 6, 3, 12)
      3.0
      >>> intercept(6, 1, 1, 6)
      7.0
      >>> intercept(4, 6, 12, 8)
      5.0
    """
if __name__== '__main__':
import doctest
doctest.testmod()
With a end result of:
*****************************************************************************
Ill have continue this tomorrow.