[Tutor] This program has worked for me before.

2012-02-08 Thread Nathaniel Trujillo
Hello, I stopped using python for about 4 months but now I am back. I tried
running my pizza_panic_game.py program again thinking nothing had changed
since a last ran it but boy was I wrong. Are we allowed to send the program
as an attachment? Here is the program

# Pizza Panic
# Player must catch falling pizzas before they hit the ground
from livewires import games, color
import random
games.init(screen_width = 640, screen_height = 480, fps =50)
class Pan(games.Sprite):

A pan controlled by player to catch falling pizzas.

image = games.load_image(pan.bmp)
def __init__(self):
 Initializing Pan object and create Text object for score. 
super(Pan, self).__init__(image = Pan.image, x = games.mouse.x,
bottom = games.screen.height)
self.score = games.Text(value = 0, size = 25, color = color.black,
top = 5, right = games.screen.width - 10)
games.screen.add(self.score)
def update(self):
 Move to mouse x position. 
self.x = games.mouse.x
if self.left  0:
self.left = 0
if self.right  games.screen.width:
self.right = games.screen.width
self.check_catch()
def check_catch(self):
 Check if catch pizzas. 
for pizza in self.overlapping_sprites:
self.score.value += 10
self.score.right = games.screen.width - 10
pizza.handle_caught()
class Pizza(games.Sprite):

A pizza which falls to the ground.

image = games.load_image(pizza.bmp)
speed = 1
def __init__(self, x, y = 90):
 Initialize a Pizza object. 
super(Pizza, self).__init__(image = Pizza.image, x = x, y = y, dy =
Pizza.speed)
def update(self):
 Check if bottom edge has reached screen bottom. 
if self.bottom  games.screen.height:
self.end_game()
self.destroy()
def handle_caught(self):
 Destroy self if caught. 
self.destroy()
def end_game(self):
 End the game. 
end_message = games.Message(value = Game Over, size = 90, color =
color.red, x = games.screen.width/2, y = games.screen.height/2, lifetime =
5 * games.screen.fps, after_death = games.screen.quit)
games.screen.add(end_message)
class Chef(games.Sprite):

A chef which moves left and right, dropping pizzas.

image = games.load_image(chef.bmp)
def __init__(self, y = 55, speed = 2, odds_change = 200):
 Initialize the Chef object. 
super(Chef, self).__init__(image = Chef.image, x =
games.screen.width / 2, y = y, dx = speed)
self.odds_change = odds_change
self.time_til_drop = 0
def update(self):
 Determined if direction needs to be reversed. 
if self.left  0 or self.right  games.screen.width:
self.dx = -self.dx
elif random.randrange(self.odds_change) == 0:
self.dx = -self.dx
self.check_drop()
def check_drop(self):
 Decrease countdown or drop pizza and reset countdown. 
if self.time_til_drop  0:
self.time_til_drop -= 1
else:
new_pizza = Pizza(x = self.x)
games.screen.add(new_pizza)
# set buffer to approx 30% of pizza height, regardless of pizza
speed
self.time_til_drop = int(new_pizza.height * 1.3 / Pizza.speed)
+ 1
def main():
 Play the game. 
wall_image = games.load_image(wall.jpg, transparent = False)
games.screen.background = wall_image
the_chef = Chef()
games.screen.add(the_chef)
the_pan = Pan()
games.screen.add(the_pan)
games.mouse.is_visible = False
games.screen.event_grab = True
games.screen.mainloop()
# start it up!
main()
and it keeps giving me this error message which I then googled to no avail

Traceback (most recent call last):
  File C:\Python31\pizza_panic_game.py, line 4, in module
from livewires import games, color
  File C:\Python31\lib\site-packages\livewires\games.py, line 57, in
module
import pygame, pygame.image, pygame.mixer, pygame.font, pygame.transform
  File C:\Python31\lib\site-packages\pygame\__init__.py, line 95, in
module
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.

thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Hello again. Still the same problem, different question.

2011-11-11 Thread Nathaniel Trujillo
I realize that one of you told me that there is no livewires for python
v3.1.1 but the book that I am reading teaches v3.1.1 and the code that is
presented in the book has a line that imports a module from the livewires
package. Now since the book covers v3.1.1, I would have to conclude that
the code containing the line from livewires import games should work in
version 3.1.1. They gave me a website to go and download a version of
livewires that would work (www.courseptr.com/downloads) and I went there
but I could not find that download anywhere. I think the website might have
changed since the book was written. If anybody knows where I can get the
version of livewires I need I would be truly greatful. My book is entitled
Python Programming for the Absolute Beginner Third Edition. Anyway, here is
the code that my book insists should work.

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
and here is the error message I keep getting

Traceback (most recent call last):
  File C:\Python27\new_graphics_window.py, line 6, in module
games.init(screen_width = 640, screen_height = 480, fps = 50)
AttributeError: 'module' object has no attribute 'init'

Someone there told me they would've given up by now but I am not giving up
on this one or anything else. Just to give you a heads up, you will be
getting questions about this until this program works. Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting ImportError: No module named beginners

2011-11-10 Thread Nathaniel Trujillo
First I typed help() into the python 3.1.1 interpreter and then I typed
modules to see if there was a beginners module and it wasn't there but when
I went into the
C:\Python31\Lib\site-packages\livewires folder I saw the file beginners.py
right there in front of my face. So here is the program I am trying to
run...

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(sreen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
and here is the error message...

Traceback (most recent call last):
  File C:\Python31\new_graphics_window.py, line 4, in module
from livewires import games
  File C:\Python31\lib\site-packages\livewires\__init__.py, line 30, in
module
from beginners import *
ImportError: No module named beginners

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Nathaniel Trujillo
Could you tell me where I can get a free download of livewires for python
version 3.1.1 ? And one that does not have a trial period please. I looked
and looked but all I found was the one for version 2.x. I thought I had the
one for version 3.1.1 but I guess I was wrong. I don't know if I am
directing this question to the right people so if not I apologize for any
inconvenience.

Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] My response to How do I get livewires for python version 3.1.1 ?

2011-11-10 Thread Nathaniel Trujillo
I actually am not familiar with python enough to know what code to use.
Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sifting through a long program

2011-11-10 Thread Nathaniel Trujillo
How do I get to line 362 of a program without counting each line ?  Thanks
for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
I decided to try using python version 2.1.3 with pygame version 1.7.1 (I
hope they're compatable) and the livewires version that was available at
livewires.org.uk, I think it's version 2.1 . After getting the following
error message I tried researching the problem myself at bing.com and then
google.com. I typed the error into both search engines but the info that I
got just led to more questions. For example, the suggestion that I thought
most applied to me was to reset the PYTHONPATH to the directory that
contains the module games.py but that led to the question how do I do that.
So I tried typing help() but that doesn't work in version 2.1.3 so I went
to google and typed how to reset PYTHONPATH in python 2.1.3 and I also
typed how to reset PYTHONPATH and didn't find much. I was told not to
make a new email or change the subject line (which to me basically means to
reply) but I was also told by someone not to reply and to make a new email
so I didn't know what to do? Also, python is my first language and I
started out knowing absolutely nothing about programming so please bare
with me. Thanks.

here is the code

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.mainloop()

and here is the error message. I appologize but the error message refered
to above is not the same one I just got after running the program again to
copy the error messge but here is the message anyway. Actually come to
think of it, the first message was

ImportError: cannot import name games

and the one I just got is

Traceback (most recent call last):
  File string, line 1, in ?
  File C:\Python21\new_graphics_window.py, line 4, in ?
from livewires import games
  File C:\Python21\livewires\games.py, line 59, in ?
import pygame, pygame.transform, pygame.draw
ImportError: No module named pygame

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay, I typed into the command line of version 2.7.2, python -c import
sys; print sys.version. I tried it with and without the quotes. I tried
copying the error messages from the command line but it wouldn't let me so
I copied them from the python shell instead.

here is what I got after typing it in with the quotes

SyntaxError: invalid syntax

and I got the same exact message when I typed it in without the quotes.
This happened in both the command line and the shell.

So that's what I got so far. Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay, I typed in python -c import sys; print sys.version at the command
prompt. I didn't see a prompt ending with %. Instead I saw a prompt ending
with . But here is the message I got.

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\net2010python -c import sys; print sys.version
'python' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\net2010

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Okay, this time I tried doing a little research but no luck in solving this one.

2011-11-10 Thread Nathaniel Trujillo
Okay this time I think it worked because it said

2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]

then I typed python at the command prompt and the little  came up. Then
I typed import pygame but I did not get an error, it just prompted me again
like this .

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about graphics.

2011-11-09 Thread Nathaniel Trujillo
I installed livewires for python 2.x so should that work with python
version 2.7.2 ? I typed in the code you see below and got the following
error message.

Here is the code.

from livewires import games

and here is the error message

Traceback (most recent call last):
  File C:/Python27/new_graphics_window.py, line 4, in module
from livewires import games
ImportError: No module named livewires

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Another question about graphics.

2011-11-09 Thread Nathaniel Trujillo
I am using python version 2.7.2. I put the version of livewires for python
2.x in the right folder this time and after running the following program I
got a different error message. Here they are.

program

# New Graphics Window
# Demonstrates creating a graphics window
from livewires import games
games.init(screen_width = 640, screen_height = 480, fps = 50)
games.screen.mainloop()
error message

Traceback (most recent call last):
  File C:/Python27/new_graphics_window.py, line 6, in module
games.init(screen_width = 640, screen_height = 480, fps = 50)
AttributeError: 'module' object has no attribute 'init'

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Another question about GUI applications.

2011-11-08 Thread Nathaniel Trujillo
I tried the code you suggested and I got the following error message.

Here is the code I tried.

root = Tkinter.Tk()
root.iconbitmap(default=ico_image_filename)

And here is the error message.

Traceback (most recent call last):
  File C:\Python31\mad_lib.py.py, line 112, in module
root = Tkinter.Tk()
NameError: name 'Tkinter' is not defined

Thanks for the help.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about GUI applications.

2011-11-07 Thread Nathaniel Trujillo
I just wrote the following GUI application. How do I get rid of the 7k in
the upper left hand corner and how to I put other stuff there like say a
picture of someone. Thanks for the help.

Here is the GUI application. It is called mad_lib.py.py

# Mad Lib
# Create a story based on user input
from tkinter import *
class Application(Frame):
 GUI application that creates a story based on user input. 
def __init__(self, master):
 Initialize Frame. 
super(Application, self).__init__(master)
self.grid()
self.create_widgets()
def create_widgets(self):
 Create widgets to get story infomation and to display story. 
# create instruction label
Label(self, text = Enter information for a new story).grid(row =
0, column = 0, columnspan = 2, sticky = W)
# create a label and text entry for the name of a person
Label(self, text = Person: ).grid(row = 1, column = 0, sticky = W)
self.person_ent = Entry(self)
self.person_ent.grid(row = 1, column = 1, sticky = W)
# create a label and text entry for a plural noun
Label(self, text = Plural Noun:).grid(row = 2, column = 0, sticky
= W)
self.noun_ent = Entry(self)
self.noun_ent.grid(row = 2, column = 1, sticky = W)
# create a label and text entry for a verb
Label(self, text = Verb:).grid(row = 3, column = 0, sticky = W)
self.verb_ent = Entry(self)
self.verb_ent.grid(row = 3, column = 1, sticky = W)
# create a label for adjectives check buttons
Label(self, text = Adjective(s):).grid(row = 4, column = 0,
sticky = W)
# create itchy check button
self.is_itchy = BooleanVar()
Checkbutton(self, text = itchy, variable =
self.is_itchy).grid(row = 4, column = 1, sticky = W)
# create joyous check button
self.is_joyous = BooleanVar()
Checkbutton(self, text = joyous, variable =
self.is_joyous).grid(row = 4, column = 2, sticky = W)
# create electric check button
self.is_electric = BooleanVar()
Checkbutton(self, text = electric, variable =
self.is_electric).grid(row = 4, column = 3, sticky = W)
# create a label for body parts radio buttons
Label(self, text = Body Part:).grid(row = 5, column = 0, sticky =
W)
# create variable for single body part
self.body_part = StringVar()
self.body_part.set(None)
# create body part radio buttons
body_parts = [bellybutton, big toe, medulla oblongata]
column = 1
for part in body_parts:
Radiobutton(self, text = part, variable = self.body_part, value
= part).grid(row = 5, column = column, sticky = W)
column += 1
# create a submit button
Button(self, text = Click for story, command =
self.tell_story).grid(row = 6, column = 0, sticky = W)
self.story_txt = Text(self, width = 75, height = 10, wrap = WORD)
self.story_txt.grid(row = 7, column = 0, columnspan = 4)
def tell_story(self):
 Fill text box with new story based on user input. 
# gets values fom the GUI
person = self.person_ent.get()
noun = self.noun_ent.get()
verb = self.verb_ent.get()
adjectives = 
if self.is_itchy.get():
adjectives += itchy, 
if self.is_joyous.get():
adjectives += joyous, 
if self.is_electric.get():
adjectives += electric, 
body_part = self.body_part.get()
# create the story
story = The famous explorer 
story += person
story +=  had nearly given up a life-long quest to find The Lost
City of 
story += noun.title()
story +=  when one day, the 
story += noun
story +=  found 
story += person + .
story += A strong, 
story += adjectives
story += peculiar feeling overwhelmed the explorer. 
story += After all this time, the quest was finally over. A tear
came to 
story += person + 's 
story += body_part + . 
story += And then, the 
story += noun
story +=  promptly devoured 
story += person + .
story += The moral of the story? Be careful what you 
story += verb
story +=  for.
# display the story
self.story_txt.delete(0.0, END)
self.story_txt.insert(0.0, story)
# main
root = Tk()
root.title(Mad Lib)
app = Application(root)
root.mainloop()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Having trouble visiting the subscribers list.

2011-11-05 Thread Nathaniel Trujillo
I recently subscribed to tutor and I am trying to visit the subscribers
list so I can ask a question but I was'nt given an admin address. Not only
that but I don't know what an admin address is. Your help is greatly
appreciated.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] getting nasty TypeError:

2011-11-05 Thread Nathaniel Trujillo
Hello. I am currently working with Python version 3.1.1 . I am working out
of the book called Python Programming for the Absolute Beginner Third
Edition which teaches version 3.1.1 . I wrote the following blackjack
program that is on page 275 and I imported the modules that you see below.
First the cards module which is on page 271 and then the games module which
is on page 268. I tried typing everything in exactly the way it is in the
book but when I run the blackjack program that you see below it will first
ask me how many players just like it should, then I tell it how many
players, then it will ask me the names of each player just like it should,
then I tell it the name of each player and after I do that and press enter
I get the following error message.

Traceback (most recent call last):
  File C:\Python31\blackjack.py, line 184, in module
main()
  File C:\Python31\blackjack.py, line 181, in main
game.play()
  File C:\Python31\blackjack.py, line 132, in play
print(player)
  File C:\Python31\blackjack.py, line 34, in __str__
rep = self.name + \t + super(BJ_Hand, self).__str__()
TypeError: can only concatenate list (not str) to list

Here is the blackjack program. It is called blackjack.py

# Blackjack
# From 1 to 7 players compete against a dealer
import cards, games
class BJ_Card(cards.Card):
 A Blackjack Card. 
ACE_VALUE = 1
@property
def value(self):
if self.is_face_up:
v = BJ_Card.RANKS.index(self.rank) + 1
if v  10:
v = 10
else:
v = None
return v
class BJ_Deck(cards.Deck):
 A Blackjack Deck. 
def populate(self):
for suit in BJ_Card.SUITS:
for rank in BJ_Card.RANKS:
self.cards.append(BJ_Card(rank, suit))
class BJ_Hand(cards.Hand):
 A Blackjack Hand. 
def __init__(self, name):
super(BJ_Hand, self).__init__()
self.name = name
def __str__(self):
rep = self.name + \t + super(BJ_Hand, self).__str__()
if self.total:
rep += ( + str(self.total) + )
return rep
@property
def total(self):
# if a card in the hand has value of None, then total is None
for card in self.cards:
if not card.value:
return None
# add up card values, treat each Ace as 1
t = 0
for card in self.cards:
t += card.value
# determine if hand contains an Ace
contains_ace = False
for card in self.cards:
if card.value == BJ_Card.ACE_VALUE:
contains_ace = True
# if hand contains Ace and total is low enough, treat Ace as 11
if contains_ace and t = 11:
# add only 10 since we've already added 1 for the Ace
t += 10
return t
def is_busted(self):
return self.total  21
class BJ_Player(BJ_Hand):
 A Blackjack Player. 
def is_hitting(self):
response = games.ask_yes_no(\n + self.name + , do you want a
hit? (Y/N): )
return response == y
def bust(self):
print(self.name, busts.)
self.lose()
def lose(self):
print(self.name, loses.)
def win(self):
print(self.name, wins.)
def push(self):
print(self.name, pushes.)
class BJ_Dealer(BJ_Hand):
 A Blackjack Dealer. 
def is_hitting(self):
return self.total  17
def bust(self):
print(self.name, busts.)
def flip_first_card(self):
first_card = self.cards[0]
first_card.flip()
class BJ_Game(object):
 A Blackjack Game. 
def __init__(self, names):
self.players = []
for name in names:
player = BJ_Player(name)
self.players.append(player)
self.dealer = BJ_Dealer(Dealer)
self.deck = BJ_Deck()
self.deck.populate()
self.deck.shuffle()
@property
def still_playing(self):
sp = []
for player in self.players:
if not player.is_busted():
sp.append(player)
return sp
def __additional_cards(self, player):
while not player.is_busted() and player.is_hitting():
self.deck.deal([player])
print(player)
if player.is_busted():
player.bust()
def play(self):
# deal initial 2 cards to everyone
self.deck.deal(self.players + [self.dealer], per_hand = 2)
self.dealer.flip_first_card()   # hide dealer's first card
for player in self.players:
print(player)
print(self.dealer)
# deal additional cards to players
for player in self.players:
self.__additional_cards(player)
self.dealer.flip_first_card()   # reveal dealer's first
if not self.still_playing:
# since all players have busted, just show the dealer's hand
print(self.dealer)
else:
# deal additional cards to dealer