Re: [Tutor] help, complete beginner please!

2010-08-28 Thread Alan Gauld


"kevin hayes"  wrote

Hi all! I'm trying to write a basic text adventure game to start 
learning
python (just for fun). I've gone through the first four chapters of 
a "learn
python game programming book" and I'm having trouble with the 
exercise on

writing a text adventure.


Sorry I don't know the book but...

I'm looking for the simplest version of this as possible, 
because

I'm having trouble with the concepts.


What is your programming background? Have you programmed in
any other language before or is Python your fist?

an idea where I'm at. However, I would really like someone to lay 
out a

little code structure for me.


I think you are maybe trying to run too fast.

Its good practice in programming to build things up slowly, pece by 
piece.
In your case forget about the loop initially. Just write the 
individual functions

and test each one individually. Once you get the functions working on
their own you can start to build the structure to call them. [This 
approach

is known as bottom-up programming in case you are interested]

This approach is particularl;y powerful in a language like Python 
because
if you put the functions in a file you can import that file as a 
module

(have you covered modules yet?)

Then at the intreractive prompt(>>>) you can interactively test your
functions to check they work.



keepGoing = True
while keepGoing == True:

   global gold


You don;t need this global is only used inside a function definition
so that the function can modify variables outside the function.
You are not inside a function at this point.


   gold = 0

   def RoomOne():


Here you are defining a function inside the while loop.
So you will redefine the function every time through the loop.
This is wasteful and not needed. Take the definition
outside the loop.

   print "You find yourself in a large room. Above you is a 
massive

crystal"
   print "chandelier. In front of you is round stone fountain, 
spewing

water"
   print "from it's center. On the walls hang green satin 
drapery.  The

ceiling"
   print "is comprised of three ornate arches. There is an arch 
in

front of you"
   print "and to your right and left. A staircase leads up from 
under

the arch"
   print "in front of you. Under the arches to your left and 
right are

large wooden"
   print "doors, each with an iron handle. Enter 'Help' for a 
full list

of commands."


Use a triple quoted string to avoid multiple print statements.


   RoomOne()
   Command = raw_input("Please enter a command. ")
   Command = Command.upper()
   if Command == "N":
   RoomFour()
   elif Command == "S":
   print "You ditched the creepy castle and headed for the 
road."

   keepGoing == False
   elif Command == "E":
   RoomTwo()
   elif Command == "HELP":
   print "List of Commands: 'Help',then enter for this list."
   print   "'N', then enter = Door to the 
North."
   print   "'S', then enter = Door to the 
South."

   print   "'E', then enter = Door to the East."
   print   "'W', then enter = Door to the West."
   print   "'Look at', then 'objects name', then 
enter

= Looks at an object."
   print   "'Pick Up', then 'objects name', then 
enter

= Picks up an object."
   print   "'Q', then enter = Quit Game."

   elif Command == "W":
   RoomSix()
   elif Command == "LOOK AT FOUNTAIN":
   print "There appears to be 4 gold coins in it."
   elif Command == "PICK UP 4 GOLD COINS":
   gold = gold + 4
   print "Current Gold = ", gold
   elif Command == "Q":
   keepGoing = False

   else:
   print "That doesn't work."

   def RoomTwo():
   print "Current Gold = ", gold
   print "In the middle of the room is a large Gargoyle with 
fiery red

eyes."
   print "He's holding a cup. In the southeast corner of the 
room you

see a broom"
   print "with dust and cob-webs on it. Next to the broom is a 
dead

rat."
   print "To the north is another door. In front of the door is 
an

overturned basket."

   promptTwo = raw_input("What are you going to do? ")
   promptTwo = promptTwo.upper()

   if promptTwo == "N":
   RoomThree()
   elif promptTwo == "S":
   print "There is no door there."
   elif promptTwo == "W":
   RoomOne()
   elif promptTwo == "E":
   print "There is only a wall there."
   elif promptTwo == "Q":
   keepGoing = False
   elif promptTwo == "PICK UP BASKET":
   print "You pick up the basket, revealing 2 gold pieces."
   RoomTwo()
   elif promptTwo == "PICK UP 2 GOLD COINS":
   gold = gold + 2
   print "Current Gold = ", gold
   RoomTwo()
   elif promptTwo == "LOOK AT GARGOYLE":
   print "Looking at the Gargoyle you notice he's really mean, 
and

really still."
   RoomTwo()
   elif promptTwo == "LOOK AT BROOM":
   print "Looking at the broom, you notice it's u

[Tutor] import prroblem

2010-08-28 Thread Roelof Wobben

Hello, 

Im trying to do a import on a linux machine.
But now Im gettting this message :

Python 2.6.5 (r265:79063, Apr  1 2010, 05:28:39) 
[GCC 4.4.3 20100316 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import calender
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named calender
>>> 

But the module calender exist
I can be found here : /usr/lib/python26/site-packages

How to solve this one ?

Roelof

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


Re: [Tutor] import prroblem

2010-08-28 Thread Joel Goldstick
But the module calender exist
> I can be found here : /usr/lib/python26/site-packages
>
> How to solve this one ?
>
> Roelof
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
it is spelled wrong -- should be calendar


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import problem

2010-08-28 Thread christopher . henk
tutor-bounces+christopher.henk=allisontransmission@python.org wrote on 
08/28/2010 12:54:28 PM:

> Hello, 
> 
> Im trying to do a import on a linux machine.
> But now Im gettting this message :
> 
> Python 2.6.5 (r265:79063, Apr  1 2010, 05:28:39) 
> [GCC 4.4.3 20100316 (prerelease)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import calender
> Traceback (most recent call last):
>   File "", line 1, in 
> ImportError: No module named calender
> >>> 

Did you try calendar (with an 'a')?  it might have just been a spelling 
mistake in your import

Can you do other imports from site-packages?


Chris___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help, complete beginner please! CORRECTION

2010-08-28 Thread bob gailer
 Thanks to Luke for pointing out that Room1() did not return anything. 
I now add a return statement:


9) have the functions return text rather than printing it. Use triple 
quoted text. e.g.:


def Room1():
  description = """You find yourself in a large room. Above you is a 
massive crystal

chandelier. In front of you is round stone fountain, spewing water."""
   return description


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] import prroblem

2010-08-28 Thread Roelof Wobben



> Date: Sat, 28 Aug 2010 10:24:06 -0700
> Subject: Re: [Tutor] import prroblem
> From: thud...@opensuse.us
> To: rwob...@hotmail.com
> 
> On Sat, Aug 28, 2010 at 9:54 AM, Roelof Wobben  wrote:
> > Hello,
> >
> > Im trying to do a import on a linux machine.
> > But now Im gettting this message :
> >
> > Python 2.6.5 (r265:79063, Apr  1 2010, 05:28:39)
> > [GCC 4.4.3 20100316 (prerelease)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
>  import calender
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > ImportError: No module named calender
> 
> >
> > But the module calender exist
> > I can be found here : /usr/lib/python26/site-packages
> >
> > How to solve this one ?
> 
> Spell it "calendar" if you want the one in the standard library.

Hello Everyone,

I was a stupid typo from me.
Sorry for the troubles,

Roelof

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


Re: [Tutor] Trouble with exercise regarding classes

2010-08-28 Thread Andrew Martin
Ok I think I got it. Thanks everybody. And sorry for the late reply. My
classes have just started so learned python unfortunately must be bumped
down on the priority list

On Thu, Aug 26, 2010 at 4:32 AM, Alan Gauld wrote:

>
> "Andrew Martin"  wrote
>
>  I want to compare zenith, a floating point number, with the current y
>> value?
>> I thought the current y value could be retrieved by Projectile.getY.
>>
>
> Projectile.getY is a reference to the getY method of the Projectile class.
> (See the separate thread on function objects for more on this topic)
>
> You want to execute the method so you need parens on the end.
>
> But, you also want to execute it for the cball instance.
> You have already done this earlier in your code, here:
>
>while cball.getY() >= 0:
>

> So you just need to make the if test compatible with that:
>
>
> if Projectile.getY > zenith:
>>>
>>
> becomes
>
>   if cball.getY() > zenith:
>
> And similarly for the assignment
>
>zenith = Projectile.getY()
>
 becomes
>   zenith = cball.getY()
>
>
> As an aside you can do this using Projectile, but its bad practice:
>
> Projectile.getY(cball)
>
> This explicitly provides the self argument instead of Python doing
> it for you when you use the instance. We can use this technique when
> calling inherited methods inside a class method definition. Anywhere
> else its best to use the instance to call a method.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] import problem

2010-08-28 Thread Nitin Das
it is >>> import calendar not calender

--nitin

On Sat, Aug 28, 2010 at 10:51 PM,
wrote:

>
>
> tutor-bounces+christopher.henk=allisontransmission@python.org wrote on
> 08/28/2010 12:54:28 PM:
>
> > Hello,
> >
> > Im trying to do a import on a linux machine.
> > But now Im gettting this message :
> >
> > Python 2.6.5 (r265:79063, Apr  1 2010, 05:28:39)
> > [GCC 4.4.3 20100316 (prerelease)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> import calender
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > ImportError: No module named calender
> > >>>
>
> Did you try calendar (with an 'a')?  it might have just been a spelling
> mistake in your import
>
> Can you do other imports from site-packages?
>
>
> Chris
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor