Re: [Tutor] question about import statement

2010-08-27 Thread Alan Gauld


"Bill Allen"  wrote


*from tkinter import *
from tkinter import ttk

These two lines tell Python that our program needs two modules. The 
first,
"tkinter", is the standard binding to Tk, which when loaded also 
causes the
existing Tk library on your system to be loaded. The second, "ttk", 
is
Python's binding to the newer "themed widgets" that were added to Tk 
in 8.5.


Yes, they are both modules so must both be imported. You could also 
do:


import tkinter as tk
import tkinter.ttk as ttk

which is the style I tend to use for my own code.

HTH,

Alan G 



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


Re: [Tutor] question about import statement

2010-08-27 Thread Peter Otten
Greg Bair wrote:

> On 08/26/2010 10:29 PM, Hugo Arts wrote:
>> On Thu, Aug 26, 2010 at 9:16 PM, Bill Allen  wrote:
>>>
>>> I did try that and of course it gave an error because it was necessary. 
>>> I
>>> just did not know why.   However, I later found an explanation on the
>>> web. Here it is:
>>>
>>> from tkinter import *
>>> from tkinter import ttk
>>>
>>> These two lines tell Python that our program needs two modules. The
>>> first, "tkinter", is the standard binding to Tk, which when loaded also
>>> causes the existing Tk library on your system to be loaded. The second,
>>> "ttk", is Python's binding to the newer "themed widgets" that were added
>>> to Tk in 8.5.
>>>
>> 
>> yeah, "from package import *" doesn't actually import every name from
>> a module. For example, by default, names starting with an underscore
>> are not imported. Alternatively, if you have a variable named __all__
>> in your module, and it's a list of names, only those names in the list
>> actually get imported when you do a "from x import *"
>> 
>> Hugo
> Why would the person who wrote this package choose to do it this way,
> though?  If it was something that people would use and not just an
> internal name, why hide it this way?

There are many programs out there that don't use ttk. For those it would be 
a waste of time and memory if the tkinter.ttk module were imported 
automatically. If you modify your example to

from tkinter import *
root = Tk()
button = Button(root, text="Hello World").grid()
root.mainloop()

it will still work (but maybe look a little different). If the ttk import 
were automatic the above script might not work on machines that don't have 
"themed widgets" even though it doesn't use them. 

In general it is good practice that modules introduce as few dependencies as 
possible.

Peter

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


Re: [Tutor] exercise problem

2010-08-27 Thread Roelof Wobben


 


From: rwob...@hotmail.com
To: alan.ga...@btinternet.com
Subject: RE: [Tutor] exercise problem
Date: Fri, 27 Aug 2010 07:04:39 +





 
> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Thu, 26 Aug 2010 23:54:19 +0100
> Subject: Re: [Tutor] exercise problem
> 
> "Roelof Wobben"  wrote
> 
> > Write a function add_vectors(u, v) that takes two lists of numbers
> 
> > I think that u is the name of the new list and v is the number which
> > represent the number which must be eveluated.
> 
> No. It sounds like you don't really understand the basic concepts
> behind functions yet. Try reading the Modules and Functions topic
> in my tutorial. See if that clarifies things for you. Getting these 
> basic
> concepts right at the beginning is very important, don't try to rush 
> it.
> 
> If confused by one tutorial reading an alternative explanation can
> often help - at least it does for me! :-)
> 
> -- 
> 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

Hello, 
 
I read your page and I think I understand the basic concepts.
What I don't see is what s and v represent.
 
My new idea is that u is the number which must be calculated and v is the 
vector which containts the outcome or u is the outcome of the first numbers and 
v the outcome of the second numbers.
 
Roelof
 
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise problem

2010-08-27 Thread Francesco Loffredo

On 27/08/2010 12.23, Roelof Wobben wrote:


From: rwob...@hotmail.com
To: alan.ga...@btinternet.com
Subject: RE: [Tutor] exercise problem
Date: Fri, 27 Aug 2010 07:04:39 +

 > To: tutor@python.org
 > From: alan.ga...@btinternet.com
 > Date: Thu, 26 Aug 2010 23:54:19 +0100
 > Subject: Re: [Tutor] exercise problem
 >
 > "Roelof Wobben"  wrote
 >
 > > Write a function add_vectors(u, v) that takes two lists of numbers
 >
 > > I think that u is the name of the new list and v is the number which
 > > represent the number which must be eveluated.
 >
 > No. It sounds like you don't really understand the basic concepts
 > behind functions yet. it does for me! :-)
 > ...
 > --
 > Alan Gauld
 > Author of the Learn to Program web site
 > http://www.alan-g.me.uk/

Hello,

I read your page and I think I understand the basic concepts.
What I don't see is what s and v represent.

My new idea is that u is the number which must be calculated and v is
the vector which containts the outcome or u is the outcome of the first
numbers and v the outcome of the second numbers.

Roelof

Ok, let's take a deep breath and start from the beginning:

First: a vector is a (usually small) ordered set of numbers that are 
taken together to represent some mathematical entity or physical 
quantity. For example, (3,1,7) can mean the position of an object in 
space, relative to a Cartesian 3-dimensional axis system.


Second: the sum of two vectors is defined as a new vector, whose 
coordinates (the elements of the vectors) are each the sum of the same 
coordinates of the two given vectors:

v1 = (a, b, c)
v2 = (x, y, z)
v1 + v2 = (a+x, b+y, c+z)

That said, Alan tried to point you to the very important concept that:
Third: a function usually produces a result in itself, using the values 
given as arguments (those inside the parentheses, in your case u and v).
And that result is usually assigned to a variable, or used directly, by 
the funcion call itself:

new_vector = add_vectors(u, v)
or
print add_vectors(u, v)

The function you want to write should sum two of these vectors, that can 
be represented in Python as tuples (or as lists, as your exercise told you):

first_vector = (3, 1, 7)
second_vector = (7, -1, 13)
result = add_vectors(first_vector, second_vector)
print result
(10, 0, 20)

So, if you are asked to write a function that "takes two lists of 
numbers", I thought that those two lists were vectors, called u and v, 
and that the result of the sum, the "new vector", would be the result 
produced by the function.


Hope this made it clearer
Francesco
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3096 -  Data di rilascio: 
08/26/10 20:34:00
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise problem

2010-08-27 Thread Steven D'Aprano
On Fri, 27 Aug 2010 08:23:06 pm Roelof Wobben wrote:
> > > Write a function add_vectors(u, v) that takes two lists of
> > > numbers
[...]
> My new idea is that u is the number which must be calculated and v is
> the vector which containts the outcome or u is the outcome of the
> first numbers and v the outcome of the second numbers. 

If you had a function called "add_numbers(x, y)", you would say that x 
and y are the numbers which are to be added. If you have a function 
called "add_vectors(u, v)", then u and v are the vectors to be added. 
Perhaps this example will help:


u = [1, 10, 100]
v = [2, 11, 111]
add_vectors(u, v)
=> [3, 21, 211]




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


Re: [Tutor] exercise problem

2010-08-27 Thread Roelof Wobben

Oke, 

 

That's also the point Alan is making.

I try now to make  the function and puttting it on this maillist if it's ready.

 

Maybe I can learn more about efficient progamming or better way to do this.

 

Roelof


 
> From: st...@pearwood.info
> To: tutor@python.org
> Date: Sat, 28 Aug 2010 00:15:15 +1000
> Subject: Re: [Tutor] exercise problem
> 
> On Fri, 27 Aug 2010 08:23:06 pm Roelof Wobben wrote:
> > > > Write a function add_vectors(u, v) that takes two lists of
> > > > numbers
> [...]
> > My new idea is that u is the number which must be calculated and v is
> > the vector which containts the outcome or u is the outcome of the
> > first numbers and v the outcome of the second numbers. 
> 
> If you had a function called "add_numbers(x, y)", you would say that x 
> and y are the numbers which are to be added. If you have a function 
> called "add_vectors(u, v)", then u and v are the vectors to be added. 
> Perhaps this example will help:
> 
> 
> u = [1, 10, 100]
> v = [2, 11, 111]
> add_vectors(u, v)
> => [3, 21, 211]
> 
> 
> 
> 
> -- 
> Steven D'Aprano
> ___
> 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] exercise problem

2010-08-27 Thread Roelof Wobben

Hello, 

 

My first try :

 

def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=1
getal1=0
getal2=0 
while teller < len(u):
getal1 = getal1 + u[teller,0] + v[teller,0]
getal2 = getal2 + v[teller,1] + v[teller,1]
teller=teller+1
return uitkomst2[getal1, getal2]

uitkomst= []
vector= [[1,0], [1,1]]
v=vector[0]
u=vector[1]
uitkomst = add_vectors[u,v]

 

But now I get this error message :

 

Traceback (most recent call last):
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 27, in 
uitkomst = add_vectors[u,v]
TypeError: 'function' object is not subscriptable
 
So it seems that I can't use vectors as a variable in a function.
 
Roelof
 
 
 

 


 


From: rwob...@hotmail.com
To: tutor@python.org
Subject: RE: [Tutor] exercise problem
Date: Fri, 27 Aug 2010 14:38:23 +




Oke, 
 
That's also the point Alan is making.
I try now to make  the function and puttting it on this maillist if it's ready.
 
Maybe I can learn more about efficient progamming or better way to do this.
 
Roelof

 
> From: st...@pearwood.info
> To: tutor@python.org
> Date: Sat, 28 Aug 2010 00:15:15 +1000
> Subject: Re: [Tutor] exercise problem
> 
> On Fri, 27 Aug 2010 08:23:06 pm Roelof Wobben wrote:
> > > > Write a function add_vectors(u, v) that takes two lists of
> > > > numbers
> [...]
> > My new idea is that u is the number which must be calculated and v is
> > the vector which containts the outcome or u is the outcome of the
> > first numbers and v the outcome of the second numbers. 
> 
> If you had a function called "add_numbers(x, y)", you would say that x 
> and y are the numbers which are to be added. If you have a function 
> called "add_vectors(u, v)", then u and v are the vectors to be added. 
> Perhaps this example will help:
> 
> 
> u = [1, 10, 100]
> v = [2, 11, 111]
> add_vectors(u, v)
> => [3, 21, 211]
> 
> 
> 
> 
> -- 
> Steven D'Aprano
> ___
> 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] exercise problem

2010-08-27 Thread Walter Prins
Hi Roelof,

See below

On 27 August 2010 16:05, Roelof Wobben  wrote:

>
> uitkomst = add_vectors[u,v]
>
> But now I get this error message :
>
>
> Traceback (most recent call last):
> *File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 27, in
> *
>
> uitkomst = add_vectors[u,v]
>
> TypeError: 'function' object is not subscriptable
>
>
>
> So it seems that I can't use vectors as a variable in a function.
>
Carefully compare the syntax for calling your function (as in the doctest)
to what you've written above.  See the difference?  (Hint: check the type of
parentheses...)

The error message is giving you a hint -- a subscriptable item is something
like a list or array.  They use square brackets.  Function calls always use
(round) parentheses.  To python, it looks like you're trying to subcript the
function object "add_vectors", which obviously isn't possible.  Hence the
message.

Regards,

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


Re: [Tutor] exercise problem

2010-08-27 Thread bob gailer
 I have been reading your posts and responses. I find myself frustrated 
with your lack of understanding of Python fundamentals and the time and 
energy others are putting in that seems to help only a little.


I recommend you take a very basic tutorial, and be sure you understand 
the basic concepts before tackling what seems too hard for you.


Also I encourage you to take each error message and look up the topic. 
In this case


getal1 = getal1 + u[teller,0] + v[teller,0]
TypeError: list indices must be integers, not tuple

What does this error tell you?

What is a tuple? What is an integer? Where is there a tuple in this 
expression? What are you trying to do?


Look up list indexing and see if you can solve it yourself, then return 
with any questions that arise from this effort.


The more you do for yourself the faster and better you will learn and we 
will be more encouraged to help.


How does this sound to you? Will you give it a try?

--
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


[Tutor] exercise problem

2010-08-27 Thread Roelof Wobben


 Hello,
 
Thanks for pointing this out.
 
I change it to this :
 
def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=1
getal1=0
getal2=0 
while teller < len(u):
getal1 = getal1 + u[teller,0] + v[teller,0]
getal2 = getal2 + v[teller,1] + v[teller,1]
teller=teller+1
uitkomst2 = [getal1, getal2]
return uitkomst2
 
uitkomst= []
vector= [[1,0], [1,1]]
v=vector[0]
u=vector[1]
print u, v
uitkomst = add_vectors(u,v)
print uitkomst  
 
But now Im getting this message :
 


Traceback (most recent call last):
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 28, in 
uitkomst = add_vectors(u,v)
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 17, in add_vectors
getal1 = getal1 + u[teller,0] + v[teller,0]TypeError: list indices must be 
integers, not tuple
 
Roelof
 

 


Date: Fri, 27 Aug 2010 16:20:27 +0100
Subject: Re: [Tutor] exercise problem
From: wpr...@gmail.com
To: rwob...@hotmail.com
CC: tutor@python.org

Hi Roelof,

See below


On 27 August 2010 16:05, Roelof Wobben  wrote:



uitkomst = add_vectors[u,v]
 
But now I get this error message :
 

Traceback (most recent call last):File 
"C:\Users\wobben\workspace\oefeningen\src\test.py", line 27, in  
uitkomst = add_vectors[u,v]
TypeError: 'function' object is not subscriptable
 
So it seems that I can't use vectors as a variable in a function.
Carefully compare the syntax for calling your function (as in the doctest) to 
what you've written above.  See the difference?  (Hint: check the type of 
parentheses...)

The error message is giving you a hint -- a subscriptable item is something 
like a list or array.  They use square brackets.  Function calls always use 
(round) parentheses.  To python, it looks like you're trying to subcript the 
function object "add_vectors", which obviously isn't possible.  Hence the 
message.

Regards,

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


[Tutor] more on wx and tiff

2010-08-27 Thread Albert-Jan Roskam
Hi again,

Some more questions about tiff conversion. 

First, thanks for your previous replies. I cannot use IrfanView any time soon, 
nor will my boss switch to Linux. 


So I'm trying to do the conversion from tiff to png using the wx package (gif 
would also be fine, but that won't work due to copyright issues -- I pulled 
about half of my hairs out before I found that out ;-). I have to access the 
second page of the tiff file, then write it to a png file. The code below (see 
also http://codepad.org/CV9xZXgi) works for one file only. Two questions:

1--- the program gives a 'tiff library warning', which is related to multipage 
tiff files (http://libtiff.maptools.org/man/TIFFReadDirectory.3tiff.html), but 
it generates the same warning with a single page tiff. The warning is given in 
a 
little menu (annoying!). How can I prevent or suppress this warning? This is 
the 
complete warning log:
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.
17:49:54: tiff module: TIFFReadDirectory
17:49:54: TIFF library warning.

2--- the program is not closed properly (despite of the destroy() call). What 
should I do to correct this?

As always, thanks in advance for your replies.

Best wishes,
Albert-Jan


import wx, Image
import os, glob

class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
self.tifLoc = tifLoc
self.debug = True
wx.Frame.__init__(self, parent, id, title, size = (600, 800))
SECONDPAGE = 1
self.image = wx.Image(name = self.tifLoc, type = wx.BITMAP_TYPE_TIF, 
index = SECONDPAGE)
if self.debug:
h, w = self.image.GetSize()
print "Reading file '%s' of %s x %s pixels" % (self.tifLoc, h, w )
self.bitmap = wx.BitmapFromImage(self.image)
wx.EVT_PAINT(self, self.OnPaint)
self.Centre()

def OnPaint(self, event):
dc = wx.PaintDC(self)
dc.DrawBitmap(self.bitmap, 0, 0)
self.saveIt()

def saveIt(self):
pngLoc = os.path.splitext(self.tifLoc)[0] + ".png"
self.bitmap.SaveFile(pngLoc, wx.BITMAP_TYPE_PNG)

class MyApp(wx.App):

def OnInit(self):
frame = MyFrame(None, -1, 'My file')
frame.Show(False) # do not show pic
self.SetTopWindow(frame)
if frame.debug:
print "... Conversion done!"
return True

path = "d:/temp"
for f in glob.glob(os.path.join(path, "*.tif")):
tifLoc = f
app = MyApp(0)
app.MainLoop()
app.Destroy()

 Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the 
Romans ever done for us?
~~



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


Re: [Tutor] exercise problem

2010-08-27 Thread Roelof Wobben


 

> Date: Fri, 27 Aug 2010 12:00:23 -0400
> From: bgai...@gmail.com
> To: rwob...@hotmail.com
> CC: tutor@python.org
> Subject: Re: [Tutor] exercise problem
> 
> I have been reading your posts and responses. I find myself frustrated 
> with your lack of understanding of Python fundamentals and the time and 
> energy others are putting in that seems to help only a little.
> 
> I recommend you take a very basic tutorial, and be sure you understand 
> the basic concepts before tackling what seems too hard for you

 

 

I follow this basic tutorial : 
http://openbookproject.net/thinkcs/python/english2e/ch09.html

 


> 
> Also I encourage you to take each error message and look up the topic. 
> In this case
> 
> getal1 = getal1 + u[teller,0] + v[teller,0]
> TypeError: list indices must be integers, not tuple
> 
> What does this error tell you?

 

That the list index must be a integer.


> 
> What is a tuple? What is an integer? Where is there a tuple in this 
> expression? What are you trying to do?


What a tuple is i can't tell you. it's in the next chapter.

A integer is a number.

What Im trying to do is that I want all the first numbers of the vectors are 
added and all the second numbers.

 

So if I have this vector [1.0] [1,1]

I try to add 1 and 1 and after that I try to add 0 and 1 

and put the answer in a new vector.

 

 

> 
> Look up list indexing and see if you can solve it yourself, then return 
> with any questions that arise from this effort.
> 
> The more you do for yourself the faster and better you will learn and we 
> will be more encouraged to help.
> 
> How does this sound to you? Will you give it a try?


Of course I will give it a try. 

 

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

 

Roelof


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


Re: [Tutor] more on wx and tiff

2010-08-27 Thread Wayne Werner
On Fri, Aug 27, 2010 at 11:25 AM, Albert-Jan Roskam  wrote:

> Hi again,
>
> Some more questions about tiff conversion.
>
> First, thanks for your previous replies. I cannot use IrfanView any time
> soon, nor will my boss switch to Linux.
>

Have you tried using the PIL?
http://www.pythonware.com/products/pil/

import Image
i = Image.open("file.tiff")
i.save(open('file.png', 'w'), filetype='png')

I don't know if that was previously suggested, but it should work on any
platform with PIL installed.

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


Re: [Tutor] exercise problem

2010-08-27 Thread Francesco Loffredo

On 27/08/2010 17.05, Roelof Wobben wrote:

Hello,

My first try :

def add_vectors(u, v):
"""
 >>> add_vectors([1, 0], [1, 1])
[2, 1]
 >>> add_vectors([1, 2], [1, 4])
[2, 6]
 >>> add_vectors([1, 2, 1], [1, 4, 3])
[2, 6, 4]
 >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
[13, -4, 13, 5]
"""
teller=1
getal1=0
getal2=0
while teller < len(u):


Up to this point, it's a good start.

Let's address the last problem first:
> uitkomst = add_vectors[u,v]
>
> But now I get this error message :
>
> uitkomst = add_vectors[u,v]
>
> TypeError: 'function' object is not subscriptable
>
> So it seems that I can't use vectors as a variable in a function.

No, it just seems that you used brackets [] instead of parentheses () in 
the function call. When you call a function, you must follow its name 
with parentheses, even when the function doesn't need arguments.

So this line should read:
uitkomst = add_vectors(u, v)
or, if you really (really?) think the two vectors should be enclosed in 
a bigger list:

uitkomst = add_vectors([u, v]).
This is just one of the problems, I'll address the rest when you'll find 
them. Just some hints:



getal1 = getal1 + u[teller,0] + v[teller,0] ???
getal2 = getal2 + v[teller,1] + v[teller,1] ???

> teller=teller+1

Ok, while I was writing, Walter told you about parentheses, so I'll 
address your next question:


But now Im getting this message :


Traceback (most recent call last):

File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 28, in 

uitkomst = add_vectors(u,v)

File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 17, in add_vectors

getal1 = getal1 + u[teller,0] + v[teller,0]
TypeError: list indices must be integers, not tuple


When you call add_vectors, you give it u and v as arguments, and they 
are two lists, as per your requirements:

v = vector[0]  makes  v equal to the list [1, 0], and
u = vector[1]  makes  u equal to the list [1, 1].
Inside add_vectors, you want to sum the coordinates of the two vectors, 
so you should refer to each of them with their position in the list.
Just as you did with the list called vector, you should use a single 
integer to address an element also in the u and v lists inside 
add_vectors. If you use a couple of numbers separated by a comma, as you 
did, Python reads them as a tuple, and it complains. So the 2 lines that 
sum the vectors should become a single one:


getal1 = getal1 + u[teller] + v[teller]

Then you don't even need to accumulate the sum in the variable getal1, 
because you are building a list and you can store each sum in a 
different position of the new list... remember the append method of the 
lists? So that line should read:


getal1 = u[teller] + v[teller]

and getal1 should be appended to a list... uitkomst2, perhaps?



Roelof


Francesco



return uitkomst2[getal1, getal2] ???
uitkomst= []
vector= [[1,0], [1,1]]
v=vector[0]
u=vector[1]
uitkomst = add_vectors[u,v]

But now I get this error message :

uitkomst = add_vectors[u,v]

TypeError: 'function' object is not subscriptable

So it seems that I can't use vectors as a variable in a function.

Roelof
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3096 -  Data di rilascio: 
08/26/10 20:34:00
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] more on wx and tiff

2010-08-27 Thread Sander Sweers
On 27 August 2010 18:25, Albert-Jan Roskam  wrote:
> First, thanks for your previous replies. I cannot use IrfanView any time
> soon, nor will my boss switch to Linux.

Why not use graphicsmagick [1] which also provides a windows binary
[2]. You can execute it with the subprocess [3] module?

Greets
Sander

[1] http://www.graphicsmagick.org/convert.html
[2] ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/windows/README.txt
[3] http://docs.python.org/library/subprocess.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise problem

2010-08-27 Thread christopher . henk
Roelof Wobben wrote on 08/27/2010 12:18:01 PM:

> 
> 
> > Date: Fri, 27 Aug 2010 12:00:23 -0400
> > From: bgai...@gmail.com
> > To: rwob...@hotmail.com
> > CC: tutor@python.org
> > Subject: Re: [Tutor] exercise problem
> > 
> > I have been reading your posts and responses. I find myself frustrated 

> > with your lack of understanding of Python fundamentals and the time 
and 
> > energy others are putting in that seems to help only a little.
> > 
> > I recommend you take a very basic tutorial, and be sure you understand 

> > the basic concepts before tackling what seems too hard for you
> 
> 
> I follow this basic tutorial : 
http://openbookproject.net/thinkcs/python/english2e/ch09.html
> 
> 
> > 
> > Also I encourage you to take each error message and look up the topic. 

> > In this case
> > 
> > getal1 = getal1 + u[teller,0] + v[teller,0]
> > TypeError: list indices must be integers, not tuple
> > 
> > What does this error tell you?
> 
> That the list index must be a integer.
> 
> > 
> > What is a tuple? What is an integer? Where is there a tuple in this 
> > expression? What are you trying to do?
> 
> What a tuple is i can't tell you. it's in the next chapter.
> A integer is a number.
> What Im trying to do is that I want all the first numbers of the vectors 
are added and all the second numbers.
> 
> So if I have this vector [1.0] [1,1]

You seem still confused on how your parameters to your function are 
working or the assignment in general.  You do not have a vector [[1,0] 
[1,1]] being passed into your function.  You are passing in two lists 
(vectors).  The first one 'u' is [1,0] , the second 'v' is [1,1] 
part of your code below:
vector= [[1,0], [1,1]]
v=vector[0]
u=vector[1]
print u, v
uitkomst = add_vectors(u,v)

if you just print u it will show [0,1]
if you just print v it will print [1,1]

thus your code:
getal1 = getal1 + u[teller,0] + v[teller,0]
getal2 = getal2 + v[teller,1] + v[teller,1]

is not doing what you thought it would.  (the syntax is wrong also).  I am 
guessing you are trying to index a 2D matrix with this.  Section 9.18 
would show you how to do that in python.  However there is no 2D matrix in 
your function, there are 2 vectors u and v.
 
So to add the vectors you loop over the index numbers (see 9.13) in your 
tutorial. in this loop add the value referenced by the index in each list 
to each other (section 9.2), and assign it to your new list at the same 
index value (9.8).  The one thing that would catch you on the assignment 
part, is that the list you are assigning to must have an element at that 
index (I didn't see the append function mentioned in your tutorial yet). 
Therefore you must initialize the list to which you are assigning to make 
sure it is the same length as the vectors you are adding (9.12 gives a 
method for this). 
 
Hopefully that will get you a bit closer to your answer.  I would suggest 
spending time in this section and make sure you understand what each line 
is doing, since these concepts are fundamentals in python programming. 
Use the interactive session in python to quickly see what each command 
does.  Python is great in that it will give you instant feedback.

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


Re: [Tutor] exercise problem

2010-08-27 Thread Roelof Wobben

Hello, 

 

Now I have this :

 

def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=0
getal1=0
getal2=0 
while teller < len(u):
getal1 = u[teller] + v[teller]
teller=teller+1
return uitkomst2
 
uitkomst= []
uitkomst2=[]
vector= [1, 2, 1], [1, 4, 3]
v=vector[0]
u=vector[1]
uitkomst = add_vectors(u,v)
print uitkomst 


The only problem I have is to build up uitkomst2.

 

on every loop getal1 has the value of the outcome.

 

So I thought this would work

 

uitkomst2 [teller] = getal1 

 

But then i get a out of range.

 

Roelof
 


Date: Fri, 27 Aug 2010 10:19:30 -0700
From: alan.ga...@btinternet.com
Subject: Re: [Tutor] exercise problem
To: rwob...@hotmail.com










>u v, result
 
first example.
 
u : [1.0]  v: [1,1] result [2.1] 
 


OK, Great, you got that.



first split  u en v in only numbers.



No, you should leave them as lists.





Then add u[0] en v[0] and u[1] and v[1] 
put the outcome in the new  vector.

Almost except you don't know how many elements there will be so 
you need a loop to process all the elements.








outcome= [outcome u, outcome[u]
return outcome.


This confused me, the output should be:

[ u[0]+v[0], u[1]+v[1], u[2]+v[2], , [u[n]+v[n] ]

And in case you are wondering, a vector is used in math to, 
for example, represent a point in space. A 2 dimensional 
point has an X,Y coordinate so we can create a 2 element 
vector: [x,y]

We can add, subtract and multiply vectors. Vectors can also 
be used to represent other physical measures, for example 
AC electric current has a magnitude and phase angle at any 
point in time. These two values can be combined as a vector.
We can use bigger vectors to represent, for example the 
set of inputs to a parallel port printer, so we would have a 
list of 8 binary values. Once again we can express mathematically 
the processing of this vector as a function and by applying the 
function to the vector deermine the expected output for any given input. 
That could be, for example, an ASCII character for the printer example...
They are very important in science and engineering.

The tutorial you are following does expect the reader to be quite 
math literate - it is part of a university comp sci course after all. If
you do not have a strong math background you may find some of 
the others more readable. For example mine( :-) ) does not assume 
any knowledge of math beyond basic high school level - really basic 
geometry and arithmetic.

Alan G.



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


Re: [Tutor] more on wx and tiff

2010-08-27 Thread Albert-Jan Roskam
Hi Wayne,

Yep, I considered using PIL, but that package won't read so-called Group 4 
Tiffs 
[1]. They're two-page, black-and-white scanned forms. I need part of the second 
form (i.e., the backside of a certificate). The page contains some hand-written 
info which needs to be presented in a simple data entry program, which I made 
using Tkinter.

The forms are confidential so they may not leave the company network. And the 
IT 
droids are somewhat paranoid so it's very time-consuming to get some new 
executable 'inside' the company network. Beeeh, formalities... :-(

 
[1] http://www.digitalpreservation.gov/formats/fdd/fdd24.shtml

Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the 
Romans ever done for us?
~~





From: Wayne Werner 
To: Albert-Jan Roskam 
Cc: Python Mailing List 
Sent: Fri, August 27, 2010 6:44:04 PM
Subject: Re: [Tutor] more on wx and tiff


On Fri, Aug 27, 2010 at 11:25 AM, Albert-Jan Roskam  wrote:

Hi again,
>
>Some more questions about tiff conversion. 
>
>First, thanks for your previous replies. I cannot use IrfanView any time soon, 
>nor will my boss switch to Linux. 
>
>

Have you tried using the PIL?
http://www.pythonware.com/products/pil/

import Image
i = Image.open("file.tiff")
i.save(open('file.png', 'w'), filetype='png')

I don't know if that was previously suggested, but it should work on any 
platform with PIL installed. 

HTH,
Wayne


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


Re: [Tutor] exercise problem

2010-08-27 Thread Dave Angel

(Don't top-post, it loses all the context)

Roelof Wobben wrote:
Hello, 

 


Now I have this :

 


def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=0
getal1=0
getal2=0 
while teller < len(u):

getal1 = u[teller] + v[teller]
teller=teller+1
return uitkomst2
 
uitkomst= []

uitkomst2=[]
vector= [1, 2, 1], [1, 4, 3]
v=vector[0]
u=vector[1]
uitkomst = add_vectors(u,v)
print uitkomst 



The only problem I have is to build up uitkomst2.
on every loop getal1 has the value of the outcome.
So I thought this would work

uitkomst2 [teller] = getal1 


But then i get a out of range.

  
Where did you put that statement?  Was it indented like getal1= and 
teller= ?  I doubt it.  If you don't use the value till the loop is 
over, then the subscript will be wrong, and so will the value.


The other problem is you're confusing the variables inside the function 
with the ones declared outside.  While you're learning, you should use 
different names for the two sets of variables.  So create a new variable 
inside the function, called something like result.  Give it an initial 
value, a list of the desired size.  Then assign to one of its elements 
each time through the loop.  And don't forget to change the return 
statement to return that variable instead of the confused-named one.


DaveA

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


Re: [Tutor] exercise problem

2010-08-27 Thread Roelof Wobben


 

> Date: Fri, 27 Aug 2010 14:27:34 -0400
> From: da...@ieee.org
> To: rwob...@hotmail.com
> CC: alan.ga...@btinternet.com; tutor@python.org
> Subject: Re: [Tutor] exercise problem
> 
> (Don't top-post, it loses all the context)
> 
> Roelof Wobben wrote:
> > Hello, 
> >
> > 
> >
> > Now I have this :
> >
> > 
> >
> > def add_vectors(u, v):
> > """
> > >>> add_vectors([1, 0], [1, 1])
> > [2, 1]
> > >>> add_vectors([1, 2], [1, 4])
> > [2, 6]
> > >>> add_vectors([1, 2, 1], [1, 4, 3])
> > [2, 6, 4]
> > >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
> > [13, -4, 13, 5]
> > """
> > teller=0
> > getal1=0
> > getal2=0 
> > while teller < len(u):
> > getal1 = u[teller] + v[teller]
> > teller=teller+1
> > return uitkomst2
> > 
> > uitkomst= []
> > uitkomst2=[]
> > vector= [1, 2, 1], [1, 4, 3]
> > v=vector[0]
> > u=vector[1]
> > uitkomst = add_vectors(u,v)
> > print uitkomst 
> >
> >
> > The only problem I have is to build up uitkomst2.
> > on every loop getal1 has the value of the outcome.
> > So I thought this would work
> >
> > uitkomst2 [teller] = getal1 
> >
> > But then i get a out of range.
> >
> > 
> Where did you put that statement? Was it indented like getal1= and 
> teller= ? I doubt it. If you don't use the value till the loop is 
> over, then the subscript will be wrong, and so will the value.
> 
> The other problem is you're confusing the variables inside the function 
> with the ones declared outside. While you're learning, you should use 
> different names for the two sets of variables. So create a new variable 
> inside the function, called something like result. Give it an initial 
> value, a list of the desired size. Then assign to one of its elements 
> each time through the loop. And don't forget to change the return 
> statement to return that variable instead of the confused-named one.
> 
> DaveA
> 


Hello, 

 

I put in right after getal1 = 

I have tried another solution nl. 

 

Put every outcome in a string.

Then convert the string into a list like this :

 

def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=0
getal1=0
uitkomst=""
while teller < len(u):
getal1 = u[teller] + v[teller]
uitkomst = uitkomst + str(getal1) 
teller=teller+1
uitkomst2 = list(uitkomst)
return uitkomst2
 
uitkomst= []
uitkomst2=[]
vector= [1, 2, 1], [1, 4, 3]
v=vector[0]
u=vector[1]
uitkomst = add_vectors(u,v)
print uitkomst 

 

But then I get a list of string instead of integers.

 

You say I have to make a vector and put all the values into it.

That can work only you have to know how big the vector must be.

Or work with a lot of if then.

 

Roelof

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


Re: [Tutor] exercise problem

2010-08-27 Thread Francesco Loffredo

We are close to the solution, keep trying!

On 27/08/2010 19.56, Roelof Wobben wrote:

Hello,

Now I have this :

def add_vectors(u, v):
"""
 >>> add_vectors([1, 0], [1, 1])
[2, 1]
 >>> add_vectors([1, 2], [1, 4])
[2, 6]
 >>> add_vectors([1, 2, 1], [1, 4, 3])
[2, 6, 4]
 >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
[13, -4, 13, 5]
"""
teller=0
getal1=0
getal2=0
while teller < len(u):
getal1 = u[teller] + v[teller]
teller=teller+1
return uitkomst2

uitkomst= []
uitkomst2=[]
vector= [1, 2, 1], [1, 4, 3]
v=vector[0]
u=vector[1]
uitkomst = add_vectors(u,v)
print uitkomst

The only problem I have is to build up uitkomst2.
There is no need to initialize uitkomst, because it will be created by 
the line

> uitkomst = add_vectors(u,v)
but you should create the list uitkomst2 INSIDE the add_vectors 
function. uitkomst2 is an internal storage for...

on every loop getal1 has the value of the outcome.

... that's it, for the different values that you put in getal1.
There is no more need for getal2, too.
So you could put the line
> uitkomst2=[]
in the place where you should delete
> getal2=0
that is just before the while loop.
And finally, in the loop, just before
> teller=teller+1
you need to insert the line that you haven't yet read about, but that 
you really need: (ta-dah!)


uitkomst2.append(getal1)

As you will (YOU WILL, WON'T YOU?) read in Alan's tutorial, and also in 
the one you're reading, this line extends the uitkomst2 list by adding a 
new element to its 'tail': the number getal1.

So, if you follow the flow of your function, you can see it happening:

-- BEGINNING ---
vector= [1, 2, 1], [1, 4, 3]  # maybe Python can forgive you, but
  # I would write [[1, 2, 1], [1, 4, 3]]
  # or ([1, 2, 1], [1, 4, 3]) ...
v=vector[0]  # now v = [1, 2, 1]
u=vector[1]  # now u = [1, 4, 3]
uitkomst = add_vectors(u,v)  # add_vectors is called to provide a value
teller=0
getal1=0
uitkomst2 = []
while teller < len(u):  # teller= 0, len(u) = 3, OK
getal1 = u[teller] + v[teller]  # getal1 = u[0]+v[0] = 1+1 = 2
uitkomst2.append(getal1)  # uitkomst2 is now [2]
teller=teller+1
while teller < len(u):  # teller= 1, len(u) = 3, OK
getal1 = u[teller] + v[teller]  # getal1 = u[1]+v[1] = 2+4 = 6
uitkomst2.append(getal1)  # uitkomst2 is now [2, 6]
teller=teller+1
while teller < len(u):  # teller= 2, len(u) = 3, OK
getal1 = u[teller] + v[teller]  # getal1 = u[2]+v[2] = 1+3 = 4
uitkomst2.append(getal1)  # uitkomst2 is now [2, 6, 4]
teller=teller+1
while teller < len(u):  # teller= 3, len(u) = 3, STOP!
return uitkomst2  # and finally the list uitkomst2 becomes the value
  # that the add_vectors function will provide.
uitkomst = add_vectors(u,v)  # now uitkomst becomes [2, 6, 4]
print uitkomst  # and lived happily ever after.



So I thought this would work

uitkomst2 [teller] = getal1

But then i get a out of range.

sure, because you tried to access an element in an empty list.



Roelof

Hope you got it, and keep trying!
Francesco
Nessun virus nel messaggio in uscita.
Controllato da AVG - www.avg.com
Versione: 9.0.851 / Database dei virus: 271.1.1/3096 -  Data di rilascio: 
08/26/10 20:34:00
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] exercise problem

2010-08-27 Thread Dave Angel



Roelof Wobben wrote:

Date: Fri, 27 Aug 2010 14:27:34 -0400
From: da...@ieee.org
To: rwob...@hotmail.com
CC: alan.ga...@btinternet.com; tutor@python.org
Subject: Re: [Tutor] exercise problem


The other problem is you're confusing the variables inside the function 
with the ones declared outside. While you're learning, you should use 
different names for the two sets of variables. So create a new variable 
inside the function, called something like result. Give it an initial 
value, a list of the desired size. Then assign to one of its elements 
each time through the loop. And don't forget to change the return 
statement to return that variable instead of the confused-named one.


DaveA





Hello, 

 

I put in right after getal1 = 

I have tried another solution nl. 

 


Put every outcome in a string.

Then convert the string into a list like this :

 


def add_vectors(u, v):
"""
  >>> add_vectors([1, 0], [1, 1])
  [2, 1]
  >>> add_vectors([1, 2], [1, 4])
  [2, 6]
  >>> add_vectors([1, 2, 1], [1, 4, 3])
  [2, 6, 4]
  >>> add_vectors([11, 0, -4, 5], [2, -4, 17, 0])
  [13, -4, 13, 5]
"""
teller=0
getal1=0
uitkomst=""
while teller < len(u):
getal1 = u[teller] + v[teller]
uitkomst = uitkomst + str(getal1) 
teller=teller+1

uitkomst2 = list(uitkomst)
return uitkomst2
 
uitkomst= []

uitkomst2=[]
vector= [1, 2, 1], [1, 4, 3]
v=vector[0]
u=vector[1]
uitkomst = add_vectors(u,v)
print uitkomst 

 


But then I get a list of string instead of integers.

  
You're close.  Now that you've initialized the result variable to [], 
you can use + just as you're doing.  Just take out the str() function in 
that line.  You've still got duplicate names there between that function 
and the outer level code.


There's also no need to convert uitkomst to a list, since it already is.


DaveA

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


Re: [Tutor] exercise problem

2010-08-27 Thread Alan Gauld


"Dave Angel"  wrote


while teller < len(u):
getal1 = u[teller] + v[teller]
uitkomst = uitkomst + str(getal1)
But then I get a list of string instead of integers.


You're close.  Now that you've initialized the result variable to 
[], you can use + just as you're doing.  Just take out the str() 
function in that line.  You've still got duplicate names there 
between that function and the outer level code.


You will need to make the new result a list too for + to work, like 
so:


uitkomst = uitkomst + [getal1]

Or you can just append() the answer to uitkomst

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] help, complete beginner please!

2010-08-27 Thread kevin hayes
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.  I've been piecing together what is in the book
with some examples I found online. My goal with this question is not to
necessarily make the code I've written work, but to gain a fundamental
understanding of the concepts.
Can someone show me how to organize a text-based game with these
things kept in mind:  1)Each room will be a function 2)Direction(N,S,E,W)
3)"Look at" 4)Pick Up 5)Quit 6)Accumulated Gold Coins 7) Find all the Gold
8)Win/Lose
 I'm looking for the simplest version of this as possible, because
I'm having trouble with the concepts. I'm only showing my code to give you
an idea where I'm at. However, I would really like someone to lay out a
little code structure for me.

I'm using Python 2.6.5 on a Mac Version 10.4.11 and don't consider myself
computer literate, so bear with my ignorance please.
Also, don't feel like you have to correct my code...please just
create your own example of code structure to get me on the right track.

Here is the start of my game:

"""FirstGame.py
First try at creating a text-based adventure game.  Trying to learn the
basics
of creating functions and using if and loops.
kevin: 8/27/10"""

keepGoing = True
while keepGoing == True:

global gold
gold = 0

def RoomOne():
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."
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 unnecessarity dirty."
elif promptTwo == "PICK UP BROOM":
print " You pick up the broom. But you don't notice anything
special, so you"
print "set it back down where it was."
elif promptTwo == "LOOK AT CUP":
print "You look at the cup, and find nothing of interest."
elif promptTwo == "LOOK AT DEAD RA

Re: [Tutor] help, complete beginner please!

2010-08-27 Thread aug dawg
Now, I'm no pro at programming in Python, but here's what I recommend you
do. I would have a class at the beginning to define all of the rooms, and
then have the rest of the code below that. Then, it makes it easier to
follow. In addition, I would also have a function that stores the name of
the room in a variable which can then call the "Look around" type function.
I would also have a variable that has the number of all of the gold and then
another one that has the amount of gold that the player has. I would place
the entire program in a loop so that every time the loop runs and checks if
the player has found all of the gold, and if the player has, it acts
accordingly. For example:

class rooms:
 (code for the various rooms goes here)

if all_gold != player_gold:
 do this
 (program goes here)
else:
 do this

Regarding the compass part (N, S, E, W) I would also do a bunch of if's
for each possible answer, and then an if on top of those. For example:

if value != None:
 if value == whatever_value:
  do this
 if value == other_value:
  do other thing

If you need extra help, just let me know.

On Fri, Aug 27, 2010 at 9:42 PM, 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.  I've been piecing together what is in the book
> with some examples I found online. My goal with this question is not to
> necessarily make the code I've written work, but to gain a fundamental
> understanding of the concepts.
> Can someone show me how to organize a text-based game with these
> things kept in mind:  1)Each room will be a function 2)Direction(N,S,E,W)
> 3)"Look at" 4)Pick Up 5)Quit 6)Accumulated Gold Coins 7) Find all the Gold
> 8)Win/Lose
>  I'm looking for the simplest version of this as possible, because
> I'm having trouble with the concepts. I'm only showing my code to give you
> an idea where I'm at. However, I would really like someone to lay out a
> little code structure for me.
>
> I'm using Python 2.6.5 on a Mac Version 10.4.11 and don't consider myself
> computer literate, so bear with my ignorance please.
> Also, don't feel like you have to correct my code...please just
> create your own example of code structure to get me on the right track.
>
> Here is the start of my game:
>
> """FirstGame.py
> First try at creating a text-based adventure game.  Trying to learn the
> basics
> of creating functions and using if and loops.
> kevin: 8/27/10"""
>
> keepGoing = True
> while keepGoing == True:
>
> global gold
> gold = 0
>
> def RoomOne():
> 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."
> 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
> s

Re: [Tutor] help, complete beginner please!

2010-08-27 Thread bob gailer

 On 8/27/2010 9:42 PM, 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.  I've been 
piecing together what is in the book with some examples I found 
online. My goal with this question is not to necessarily make the code 
I've written work, but to gain a fundamental understanding of the 
concepts.
Can someone show me how to organize a text-based game with 
these things kept in mind:  1)Each room will be a function 
2)Direction(N,S,E,W) 3)"Look at" 4)Pick Up 5)Quit 6)Accumulated Gold 
Coins 7) Find all the Gold 8)Win/Lose


aug dawg recommended classes, with which I agree, but that may be 
premature for you.


1) define the functions once, outside the while loop.

2) there is no need for global gold. global only makes sense inside a def.

3) do not reset gold to 0 at the start of each loop cycle. Do that 
before the loop.


4) write a help function to handle the help text rather than repeating 
the text multiple times.


5) use initial lower case for function and variable names. This is a 
convention that makes

 it easier to read each other's code as well as your own code.

6) check the spelling of wooley mamoth

7) while keepGoing == True: can be simplified to while keepGoing:

8) write a function to get a command. Have it do the uppercasing and 
checking for / processing of common commands such as HELP,


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."""

Then in the loop:
  print Room1().

This separates data from logic and paves the way to convert things to 
classes & dictionaries.



I'm looking for the simplest version of this as possible, 
because I'm having trouble with the concepts. I'm only showing my code 
to give you an idea where I'm at. However, I would really like someone 
to lay out a little code structure for me.


I'm using Python 2.6.5 on a Mac Version 10.4.11 and don't consider 
myself computer literate, so bear with my ignorance please.
Also, don't feel like you have to correct my code...please 
just create your own example of code structure to get me on the right 
track.


Here is the start of my game:

"""FirstGame.py
First try at creating a text-based adventure game.  Trying to learn 
the basics

of creating functions and using if and loops.
kevin: 8/27/10"""

keepGoing = True
while keepGoing == True:

global gold
gold = 0

def RoomOne():
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."

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."
pr