Re: [Tutor] One of my 'baby step' programs

2006-10-02 Thread Kent Johnson
Luke Paireepinart wrote:
> Alan Gilfoy wrote:
>> -code block-
>>
>> number = 3
>> running = True
>>
>> while running:
>>guess = int(raw_input("Please enter a number : ")) #lets user guess a 
>> number
>>
>>if guess == number:
>>print "Yay, you got the right number, good for you. But you 
>> don't get any prizes. Do I look like a walking ATM to you?"
>>running = False #this causes the guess-again loop to start.
>>elif guess < number:
>>print "No, my number is higher than that"
>>else:
>>print "No, my number is lower than that."
>>
>> else:
>>print "The number-guessing loop is over."
>>   
> I had no idea you could have an 'else' tied to a 'while' loop.
> Interesting

It's useful but in this case not necessary - since there is no 'break' 
within the loop, the 'else' clause will always be executed. That is 
correct behaviour in this case, so it would be better to leave out the 
else and just have the print.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] senior project

2006-10-02 Thread Kent Johnson
Alan Gilfoy wrote:
> I am a senior at the School Without Walls in Rochester, NY. As such, I 
> get to do a senior project. I decided to work on computer programming, 
> since that is sometihng that I certianly think can hold my interest 
> throughout the school year.
> 
> (despite my compute rinteresat, I've never done anything much more 
> advanced than HTML, for some reason)
> 
> One of my community advisers suggested I start with Python. (he also 
> suggested this mailing list)

Welcome to Python! And congratulations for having a great advisor ;)

> 
> So far, I've liked the 
> http://swaroopch.info/text/Byte_of_Python:Main_Page tutorial, for 
> basics.

Are you asking for more suggestions?

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeit at the command line

2006-10-02 Thread Kent Johnson
Dick Moores wrote:
> C:\>python -m timeit  -s"x=0" "while x<100:" "  x+=1"
> 1000 loops, best of 3: 0.123 usec per loop
> 
> C:\>python -m timeit -s"for x in range(100):" "x+=1"
> Traceback (most recent call last):
>File "E:\Python25\lib\runpy.py", line 95, in run_module
>  filename, loader, alter_sys)
>File "E:\Python25\lib\runpy.py", line 52, in _run_module_code
>  mod_name, mod_fname, mod_loader)
>File "E:\Python25\lib\runpy.py", line 32, in _run_code
>  exec code in run_globals
>File "E:\Python25\lib\timeit.py", line 285, in 
>  sys.exit(main())
>File "E:\Python25\lib\timeit.py", line 249, in main
>  t = Timer(stmt, setup, timer)
>File "E:\Python25\lib\timeit.py", line 116, in __init__
>  code = compile(src, dummy_src_name, "exec")
>File "", line 4
>  _t0 = _timer()
>^
> IndentationError: expected an indented block
> 
> 
> Is there a better way to indicate the indentation of "  x+=1"  (2 
> spaces in this case) ? For me, this usually works in a while loop, 
> but so far, never in a for loop.

Strange, your example works for me in Python 2.4 and 2.5:
D:\>python -m timeit  -s"x=0" "while x<100:" "  x+=1"
1000 loops, best of 3: 0.102 usec per loop

Are you using 2.5 final or one of the earlier releases?

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeit at the command line

2006-10-02 Thread Dick Moores
At 03:08 AM 10/2/2006, Kent Johnson wrote:
>Dick Moores wrote:
> > C:\>python -m timeit  -s"x=0" "while x<100:" "  x+=1"
> > 1000 loops, best of 3: 0.123 usec per loop
> >
> > C:\>python -m timeit -s"for x in range(100):" "x+=1"
> > Traceback (most recent call last):
> >File "E:\Python25\lib\runpy.py", line 95, in run_module
> >  filename, loader, alter_sys)
> >File "E:\Python25\lib\runpy.py", line 52, in _run_module_code
> >  mod_name, mod_fname, mod_loader)
> >File "E:\Python25\lib\runpy.py", line 32, in _run_code
> >  exec code in run_globals
> >File "E:\Python25\lib\timeit.py", line 285, in 
> >  sys.exit(main())
> >File "E:\Python25\lib\timeit.py", line 249, in main
> >  t = Timer(stmt, setup, timer)
> >File "E:\Python25\lib\timeit.py", line 116, in __init__
> >  code = compile(src, dummy_src_name, "exec")
> >File "", line 4
> >  _t0 = _timer()
> >^
> > IndentationError: expected an indented block
> >
> >
> > Is there a better way to indicate the indentation of "  x+=1"  (2
> > spaces in this case) ? For me, this usually works in a while loop,
> > but so far, never in a for loop.
>
>Strange, your example works for me in Python 2.4 and 2.5:
>D:\>python -m timeit  -s"x=0" "while x<100:" "  x+=1"
>1000 loops, best of 3: 0.102 usec per loop
>
>Are you using 2.5 final or one of the earlier releases?

2.5 final.

Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to make a reference to part of list?

2006-10-02 Thread Xie Chao
  Namely, if  list1 = {1, 2, 3}, and I wanna make a reference, say "ref",  to list1's sublist (which is also of type list), say {2, 3}, so that when I make change to ref[0], then list1[1] will be changed!
  But how can I make such a reference, 3x!  
 ___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My number-guessing program

2006-10-02 Thread Alan Gilfoy
Yeah, that's what the wiki-based tutorial mentioned.
In fact, Lee Harr (my community adviser) also suggested using a random number.

Quoting Luke Paireepinart <[EMAIL PROTECTED]>:

> Alan Gilfoy wrote:
(the start of the code for my number-guessing thingamajig)
>>
>> else:
>>print "The number-guessing loop is over."
>>
(some more code)

My line: number = 3
Would I use 'number = random.randint()' in place of that, to have the 
relevant number be random?


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a reference to part of list?

2006-10-02 Thread Kent Johnson
Xie Chao wrote:
>   Namely, if  list1 = {1, 2, 3}, and I wanna make a reference, say 
> "ref",  to list1's sublist (which is also of type list), say {2, 3}, so 
> that when I make change to ref[0], then list1[1] will be changed!
>   But how can I make such a reference, 3x!  

There is nothing built-in to Python that will let you do this. I don't 
think it would be too hard to write a class that does what you want for 
basic indexing operations. I would start with a copy of UserList (in 
module UserList). If you go beyond simple indexing and slicing I think 
you will have trouble. Say you have a class RefList that does what you 
want, and suppose you have
a = [1, 2, 3]
b = RefList(a, 1, 2)
b is [2, 3]
c = RefList(a, 0, 1)
c is [1, 2]

Now what is the result of d=b+c? Is it a RefList with two references to 
a, that looks like [1, 2, 2, 3]? What is the value of d after d[1] = 0? 
Is it [1, 0, 0, 3]?

Can you say more about why you want to do this? Maybe there is another 
solution.

By the way list literals in Python are written with square brackets [] 
not curly braces {}.

Kent


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a reference to part of list?

2006-10-02 Thread Xie Chao
   3Q very much!
   What I really want to get is a c-style array, a pointer to the beginning of part of a list (or whatever alike). for example, I want to mutate part of a list, of course, I can achieve this by passing the pair list and (begin, end) as parameters. but in some case, this manner is quite tedious and in efficient (I think so, at least in C-style language it is so)!
    I don't wanna get the '+' operator (which is powerful tool in scripting language), so I ignore this problem. thank you all the same!
    maybe this prolem looks silly, since I've just begun to study scripting language. 
- Original Message From: Kent Johnson <[EMAIL PROTECTED]>Cc: tutor@python.orgSent: Monday, October 2, 2006 7:57:31 PMSubject: Re: [Tutor] how to make a reference to part of list?
Xie Chao wrote:>   Namely, if  list1 = {1, 2, 3}, and I wanna make a reference, say > "ref",  to list1's sublist (which is also of type list), say {2, 3}, so > that when I make change to ref[0], then list1[1] will be changed!>   But how can I make such a reference, 3x!  There is nothing built-in to Python that will let you do this. I don't think it would be too hard to write a class that does what you want for basic indexing operations. I would start with a copy of UserList (in module UserList). If you go beyond simple indexing and slicing I think you will have trouble. Say you have a class RefList that does what you want, and suppose you havea = [1, 2, 3]b = RefList(a, 1, 2)b is [2, 3]c = RefList(a, 0, 1)c is [1, 2]Now what is the result of d=b+c? Is it a RefList with two references to
 a, that looks like [1, 2, 2, 3]? What is the value of d after d[1] = 0? Is it [1, 0, 0, 3]?Can you say more about why you want to do this? Maybe there is another solution.By the way list literals in Python are written with square brackets [] not curly braces {}.Kent___Tutor maillist  -  Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a reference to part of list?

2006-10-02 Thread Kent Johnson
Xie Chao wrote:
>3Q very much!
>What I really want to get is a c-style array, a pointer to the 
> beginning of part of a list (or whatever alike). for example, I want to 
> mutate part of a list, of course, I can achieve this by passing the pair 
> list and (begin, end) as parameters. but in some case, this manner 
> is quite tedious and in efficient (I think so, at least in C-style 
> language it is so)!
> I don't wanna get the '+' operator (which is powerful tool in 
> scripting language), so I ignore this problem. thank you all the same!
> maybe this prolem looks silly, since I've just begun to 
> study scripting language. 

Take a look at numpy, it seems to do what you want:
In [2]: from numpy import *

In [4]: a=arange(10)

In [5]: a
Out[5]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [6]: b=a[3:5]

In [7]: b
Out[7]: array([3, 4])

In [8]: b[0]=10

In [9]: b
Out[9]: array([10,  4])

In [10]: a
Out[10]: array([ 0,  1,  2, 10,  4,  5,  6,  7,  8,  9])

http://numpy.scipy.org/

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My number-guessing program

2006-10-02 Thread Luke Paireepinart

>
>
> My line: number = 3
> Would I use 'number = random.randint()' in place of that, to have the 
> relevant number be random?
yes, but remember that random.randint takes 2 arguments, the endpoints.
E.G.
random.randint(1,10)
would be equivalent to
random.choice(range(1,11))
or
random.choice([1,2,3,4,5,6,7,8,9,10])

Note that the random.randint function includes both endpoints (I.E. the 
numbers are 1-10 including 10)
but the range() function doesn't include the last endpoint.
HTH
-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to make a reference to part of list?

2006-10-02 Thread Danny Yoo


> for example, I want to mutate part of a list, of course, I can achieve 
> this by passing the pair list and (begin, end) as parameters. but in 
> some case, this manner is quite tedious and in efficient

I'm not sure what you mean by "inefficient".  What do you think a 
"pointer" is, if not what you just described?  *grin*


Conceptually, a pointer is some arrow directed at some other thing. Here's 
a possible implementation of what you're asking:

###
class ListPointer:
 def __init__(self, L, i):
 """Creates a pointer into the i'th element of L."""
 self.L = L
 self.i = i

 def deref(self):
 """Returns the value pointed to."""
 return self.L[self.i]

 def mutate(self, value):
 """Mutates the list value that we point to."""
 self.L[self.i] = value
###


For example:

#
>>> l = ["hello", "world", "testing"]
>>> p = ListPointer(l, 1)
>>> p.deref()
'world'
>>> p.mutate("universe")
>>> p.deref()
'universe'
>>> l
['hello', 'universe', 'testing']
#

At the moment, this class allows point mutations, and could probably be 
adjusted to work with slices.


That being said, can you explain what the purpose is?  There may be some 
other effective way to do what you're trying to do, without the additional 
level of indirection that pointers impose.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] database web app, what tool?

2006-10-02 Thread Eric Walstad
Hey Paulino,

I'm a Django fan but from your description, a simple CGI app might do 
nicely.  Heck, you've already got the code written, just wrap it in a 
CGI script that formats your list of records in HTML and serve the 
script from your (already setup?) apache or even from your workstation 
with Python's CGI server.

Best,

Eric.


Liam Clarke wrote:
> Paulino wrote:
> 
> Hi Paulino,
> 
> Tough question that. What is your existing web server? That'd be a good 
> starting point. Zope/Plone are great, but they have a steep learning 
> curve that doesn't seem essential to what you're doing. Django is 
> simpler, but once again, doesn't immediately fit to what you're trying 
> to do, but it could do.
> 
> I'd say just a straight mod_python would be simplest, to be honest, but 
> it really depends on what you're doing.
> 
> Regards,
> 
> Liam Clarke
>> Hi!
>>
>> Im a very biginner in programming and I started with python, witch I 
>> found much easier tahn i thought.
>>
>> I want to build an intranet page in my organization that shows some data 
>> from our financial aplication's database.
>>
>> For the starting point I would like it to show invoices lists per 
>> supplier and link each line to a pdf image of the selected invoice that 
>> is stored in a determined folder.
>>
>> The aim is only to make querys and show the results. No updates, nor 
>> insert's
>>
>> The database is MS SQL 2005
>>
>>
>>
>> Right now I connect to the database via pymssql, and i can retrieve data 
>> and send it to a wx.Grid or to a reportlab pdf file, with platypus 
>> tables (a couple of months ago i would say i'd never be able to do it... 
>> and now i want to do more...)
>>
>> Now I want to send it to the browser so the administration can see it 
>> every time they need.
>>
>>
>> What tool is more suitable?
>>
>> There are so many options!
>>
>> Zope-Plone have it's own web server, so less config is required. But i 
>> can't find any recipe or tutorial usefull for this task...
>>
>> there is also django, turbogears, webware, apache and mod-python.
>>
>>
>> Thank you
>>
>>
>> Paulino
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python code to split and reassemble files

2006-10-02 Thread Eric Walstad
Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Never mind.. :)
> 
> 
> found it at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/224800
> 
> However, if someone has something better, I would be very interested.

Hi Andrew,

If you are on a *nix machine you could use split and cat:

"""
SPLIT(1)

NAME
split - split a file into pieces

SYNOPSIS
split [OPTION] [INPUT [PREFIX]]

DESCRIPTION
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; 
default size is 1000 lines, and default PREFIX is ‘x’.
"""

"""
CAT(1)

NAME
cat - concatenate files and print on the standard output

SYNOPSIS
cat [OPTION] [FILE]...

DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
"""

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] One of my 'baby step' programs

2006-10-02 Thread John Fouhy
On 03/10/06, Alan Gilfoy <[EMAIL PROTECTED]> wrote:
>
>  for i in range(10):
> > ...  break
> > ... else:
> > ...  print 'foo'
> > ...
>  for i in range(10):
> > ...  pass
> > ... else:
> > ...  print 'foo'
> > ...
> > foo
> 
>
> pardon the newb question, but what do these code lines do?

They demonstrate when the else: clause in a for statement gets executed.

Spaces sometimes get lost in email, so I'll write them again, with
underscores instead of spaces:

for i in range(10):
break
else:
print 'foo'

In this case, the for loop will exit because of the break statement,
and so the else: clause will not execute.

for i in range(10):
pass
else:
print 'foo'

In this case, the loop body is just 'pass', which is python's
do-nothing statement.  So the loop will exit normally, and the else:
clause will execute (resulting in the string 'foo' being printed).

Does this help?

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] My number-guessing program

2006-10-02 Thread John Fouhy
On 03/10/06, Luke Paireepinart <[EMAIL PROTECTED]> wrote:
> Note that the random.randint function includes both endpoints (I.E. the
> numbers are 1-10 including 10)
> but the range() function doesn't include the last endpoint.

Which is why (in my not-so-humble opinion :-) ) we should tell people
to use random.randrange instead of random.randint!

(random.randrange takes up to 3 arguments with exactly the same
meanings as range())

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] timeit at the command line

2006-10-02 Thread Dick Moores
At 01:50 PM 10/2/2006, John Fouhy wrote:
>On 02/10/06, Dick Moores <[EMAIL PROTECTED]> wrote:
>>C:\>python -m timeit -s"for x in range(100):" "x+=1"
>>Traceback (most recent call last):
>
>The -s option specifies the setup code.  In this case, you don't have
>any setup code.  Try this:
>
>python -m timeit "for x in range(100):" " x += 1"
>
>HTH!
>
>--
>John.

Terrific!
E:\Python25\dev>python -m timeit "for x in range(100):" " x += 1"
10 loops, best of 3: 14.9 usec per loop

So with
python -m timeit  -s"x=0" "while x<100:" "  x+=1"
1000 loops, best of 3: 0.123 usec per loop

I DID have setup code, the "x=0".  I now notice that if the "x=0" is 
not stated as the setup code, the time difference is enormous, 
132-to-1 in this case.

python -m timeit  -s"x=0" "while x<100:" "  x+=1"
1000 loops, best of 3: 0.116 usec per loop

python -m timeit "x=0" "while x<100:" "  x+=1"
10 loops, best of 3: 15.3 usec per loop

Thanks, John.

Dick




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] [Fwd: Re: database web app, what tool?]

2006-10-02 Thread Liam Clarke


 Original Message 
Subject:Re: [Tutor] database web app, what tool?
Date:   Mon, 02 Oct 2006 09:33:28 +0100
From:   [EMAIL PROTECTED]
To: Liam Clarke <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]> 
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>



Thank you Liam,


Our web server is IIS, but it would be no problem to use another one for this
particular purpose.

I'v been looking for information on how to design tables for the web with
python, without succes so far. Can you point me any tutorial?


Paulino




Citando Liam Clarke <[EMAIL PROTECTED]>:

> Paulino wrote:
>
> Hi Paulino,
>
> Tough question that. What is your existing web server? That'd be a good
> starting point. Zope/Plone are great, but they have a steep learning
> curve that doesn't seem essential to what you're doing. Django is
> simpler, but once again, doesn't immediately fit to what you're trying
> to do, but it could do.
>
> I'd say just a straight mod_python would be simplest, to be honest, but
> it really depends on what you're doing.
>
> Regards,
>
> Liam Clarke
> > Hi!
> >
> > Im a very biginner in programming and I started with python, witch I
> > found much easier tahn i thought.
> >
> > I want to build an intranet page in my organization that shows some data
> > from our financial aplication's database.
> >
> > For the starting point I would like it to show invoices lists per
> > supplier and link each line to a pdf image of the selected invoice that
> > is stored in a determined folder.
> >
> > The aim is only to make querys and show the results. No updates, nor
> > insert's
> >
> > The database is MS SQL 2005
> >
> >
> >
> > Right now I connect to the database via pymssql, and i can retrieve data
> > and send it to a wx.Grid or to a reportlab pdf file, with platypus
> > tables (a couple of months ago i would say i'd never be able to do it...
> > and now i want to do more...)
> >
> > Now I want to send it to the browser so the administration can see it
> > every time they need.
> >
> >
> > What tool is more suitable?
> >
> > There are so many options!
> >
> > Zope-Plone have it's own web server, so less config is required. But i
> > can't find any recipe or tutorial usefull for this task...
> >
> > there is also django, turbogears, webware, apache and mod-python.
> >
> >
> > Thank you
> >
> >
> > Paulino
> >
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>
>


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Number guessing game

2006-10-02 Thread Christopher Hatherly
Hi, 
I'm brand new to Python, and almost brand new to programming. I'm
teaching myself slowly through a 'Python Programming for the Absolute
Beginner' book, which is great so far. One of the challenge problems
though, was to write a script for a number guessing game, where you pick
a number and the computer tries to guess. It took me a couple of days to
get this working, and some of it is pretty messy. In particular, the
'Guess = ...' line, and the 
responses[] list' that I used. I'm happy that this works, but would like
to know how to do it better! If anyone could suggest any improvements,
that'd be great! 

Cheers
Chris

 
print """
Welcome to the 'guess the Number' game!!!
Your job is to pick a number and my job is to try and figure it out."
After each guess, tell me if I'm too high or too low."
  I've only got 7 goes to guess the number though ..."
"""
 
raw_input("\nPress enter when you're ready.")
 
guess = 50
responses = [guess, 0]
guess_number = 0
number = int(raw_input("\nPick a number between 1 and 100: "))
print "\nOK, guess number", guess_number +1, "is", guess
 
while (guess != number) and guess_number < 6:
high_low = raw_input("\nToo High or too Low (H/L)? ")
 
if high_low == "H":
print "Darn, too high!"
guess =
responses[guess_number]-(round(abs(responses[guess_number]-responses[gue
ss_number-1])/2))
print "I have", 5 - guess_number, "guesses remaining."
guess_number += 1
responses = responses[:guess_number] + [guess]
raw_input ("\nPress enter to continue.")
print "\nOK, guess number", guess_number +1, "is", int(guess)
 
elif high_low == "L":
print "Darn, too low!"
guess =
responses[guess_number]+(round(abs(responses[guess_number]-responses[gue
ss_number-1])/2))
print "I have", 5 - guess_number, "guesses remaining."
guess_number += 1
responses = responses[:guess_number] + [guess]
raw_input ("\nPress enter to continue.")
print "\nOK, guess number", guess_number +1, "is", int(guess)
 
else:
print "Sorry, I didn't understand that."
 
if guess == number:
print "\nHoorah!!! I got the number!!!"
print "The number was ", number 
print "and I only took", guess_number + 1, "guesses."
else:
how_close = abs(guess - number)
print "\nToo bad. The number was", number
print "I was", int(how_close), "off getting it right."

raw_input("\n\nPress the enter key to exit.\n")

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Number guessing game

2006-10-02 Thread Luke Paireepinart
Christopher Hatherly wrote:
> Hi, 
> I'm brand new to Python, and almost brand new to programming. I'm
> teaching myself slowly through a 'Python Programming for the Absolute
> Beginner' book, which is great so far.
Awesome, I'm always happy to hear of budding pythonistas :D

>  One of the challenge problems
> though, was to write a script for a number guessing game, where you pick
> a number and the computer tries to guess. It took me a couple of days to
> get this working, and some of it is pretty messy. In particular, the
> 'Guess = ...' line, and the 
> responses[] list' that I used. I'm happy that this works, but would like
> to know how to do it better! If anyone could suggest any improvements,
> that'd be great! 
>   
As you'll see below, I didn't look through your code to comment on 
individual things.
I thought that if you saw the code I wrote you might get some new ideas 
and such,
which you could carry over and improve your own code, rather than just 
giving you
direct 'change this line to this'-type stuff.
If this doesn't help you at all and you want me to go through your code 
and comment on specific
points you could improve it, I'll certainly do so, I just thought this 
might be more helpful.



Now, I'll take you through the thinking process I'd go through to make 
this program.

First:  What is it we want the program to do?
1. Greet the user.
2. Ask the user for a number
3. Generate a number.
4. Compare this generated number with the user's number.
5.  If the generated number is the same as the user's number, goto 7.
6.  Otherwise, goto 4. repeat up to (max guesses) times, then goto 7.
7.  Tell the user if we managed to guess the number correctly.
8.  Say goodbye to the user.

Okay, let's see what variables we'll need for this.
1.  The greeting string.
2.  The user's number.
3.  The generated number.
4.  How many guesses we're allowed to make.
5.  Whether the guessing was successful.
6.  We'll also include the range to guess the numbers,
just to add an extra feature, so we'll need min and max variables.
7.  A goodbye string.

We'll also need to use the random module to generate our guesses,
so we don't always guess the same number.



#start-code.

#Number-Guesser.py
#license = Public Domain
#original author: Luke Paireepinart


#we'll need the random module to make our guesses
import random

#set up these variables we decided were necessary.
#initializing variables like this is helpful because
#it helps people who're reading your code understand what your
#variables are, for the most part, and what you'll probably use them for.
#so make sure they all have nice descriptive names.
greeting = """ Welcome to the number-guessing game.
Hope you enjoy this! Hit enter to continue.  """
goodbye = "Thanks for playing the number-guessing game!"
usernum = 0
guessednum = 0
maxguesses = 5
guessed = False
min_guess = 0
max_guess = 100


#First order of business: greeting the user.
raw_input(greeting)

#now we want to get a number from him,
#and we'll store it in our usernum variable.
#we're going to assume the nice-user scenario where they know
#that by 'number' you mean 'integer' and not 'random gibberish.'
#you could use a try: -> except: block here, if you couldn't trust
#the user.
usernum = int(raw_input("What is your number?  "))

#once we have this number, we want to start up a loop
#that will continue to guess until it either gets the number right
#or runs out of guesses.

x = 0 #x is an arbitrary loop variable.
while x < maxguesses: #we'll loop until we reach the maximum guess limit.
#we're using random.randrange because it behaves like range(), as 
John pointed out earlier.
#this means if you call 'random.randrange(0,100)' the number will be 
0 or 99 or anywhere
#in between, but not 100.  change the following line to either
#'random.randrange(min_guess,max_guess+1)' or 
'random.randint(min_guess,max_guess)'
#if you want to include both endpoints.
guessednum = random.randrange(min_guess,max_guess)

#now that we have the guessed number, let's compare it to the user's 
number.
if usernum == guessednum: #if we guessed right :)
   guessed = True
   break#let's get out of the loop since we're sure we guessed 
correctly.
elif usernum < guessednum: #we guessed too high.
   #the following line has what's called a 'string substitution.'
   #all of the '%s' items are replaced by the items in the 
parenthesis to the left of the string,
   #after the %.
   print "We guessed %s instead of %s, which is %s bigger than your 
number." % (guessednum,usernum,guessednum-usernum)
elif usernum > guessednum: #we guessed too low.
   print "We guessed %s instead of %s, which is %s less than your 
number." % (guessednum,usernum,usernum-guessednum)
   
#and finally, increment our loop-variable so we can keep track of 
how many times through
#we've gone.
x += 1

#now that the loop has ended, there are two outcomes:
#a.  we guessed correctly, and

[Tutor] What is a Python "project"?

2006-10-02 Thread Dick Moores
I tried out Wing IDE Personal 
() off and on for 30 days, and 
then, finding it easy to use (probably because it's designed for 
Python), decided to buy it. I'm happy with it, and very pleased with 
the fast response from technical support available by email.

I've never written anything in Python other than single-file scripts. 
WingIDE has the ability to handle "projects", which apparently 
consist of files and "packages". But what is a project? What does a 
project have that can't be put into a single .py file script?

Thanks,

Dick Moores

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor