Re: [Tutor] dealing with user input whose value I don't know

2008-10-03 Thread David

Hello Alan, dear list members,

Alan Gauld wrote:

The solution you have already seen - use string.split(',') to separate
the string into substrings and then convert each substring to an
integer.
This I have now done by using eval(). But now I wonder whether that is 
actually clever because it is supposed to be similarly problematic as 
the input() function in terms of security. Alternatively I could use 
int() -- would that be the way forward?


Here is the code:

def main():
   import string

   print This program takes the average of numbers you supply!!

   amount = raw_input(How many numbers do you want me to work with? )
   print You want me to take the average of, amount, numbers.

   numbers = raw_input(Please type the numbers, separated by commas: )
   print You want to know the average of the numbers:, numbers

   add = 0
   for numStr in string.split(numbers, ,):
   convNum = eval(numStr) # convert digit string to a number
   add = add + convNum # add number to variable 'add'
   print The sum of your numbers is:, add
   average = add / float(amount)
   print Therefore the average of your numbers is, average
main() 



Many thanks,

David

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


Re: [Tutor] dealing with user input whose value I don't know

2008-10-03 Thread Alan Gauld


David [EMAIL PROTECTED] wrote


the string into substrings and then convert each substring to an
integer.
This I have now done by using eval(). But now I wonder whether that 
is actually clever because it is supposed to be similarly 
problematic as the input() function in terms of security.


Absolutely. The more open and general you make your code
the more opportunity you provide for attacks. Converting to
int/float is much safer.

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



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


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread W W
On Fri, Oct 3, 2008 at 12:44 AM, Tim Peters [EMAIL PROTECTED] wrote:

 [Alec Henriksen]
  How trustworthy is the randomness generated by the random module?

 Python uses the Mersenne Twister algorithm for generating
 pseudo-random numbers, and that's one of the highest-quality methods
 known.


I've talked with some people about random number generation, and how you can
tell if it's random. For 10 numbers, is 5 5 5 5 5 5 5 5 5 5 random? You
really don't know, because it's random! It probably is. Even if the set
before and after are all the same, it still could be - that's the beauty of
randomness, is sometimes you can get what looks like patterns.

Of course, if you're working with data encryption, this is simply not a very
reliable way to do things. One of the most random ways (of course if you
were able to /exactly/ duplicate the circumstances, you'd still get the same
result. However it's much more difficult to duplicate the circumstances with
this method.) I've seen to generate a number is getting sound input from the
mic jack when there's no mic attached, and treating it like string data,
then using that as your key.

Hooray for Random!
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread nathan virgil
Hm... Tried changing that, but it didn't help

On Thu, Oct 2, 2008 at 9:18 AM, Luke Paireepinart [EMAIL PROTECTED]wrote:

 room == start is a comparison (check if room is equal to start - doesn't
 make a whole lot of sense to be doing that here).  The room variable name
 doesn't exist in the current namespace, so it can't be compared to start.
 It looks like you wanted room = start.

 On 10/2/08, nathan virgil [EMAIL PROTECTED] wrote:

 Okay, I'm resurrecting this project. I did a little more work on it then
 what you see here, but that ended up getting accidentally deleted, and I
 haven't done anything with Python since.

 I'm running into one problem already, and I haven't really added any extra
 code. In the content (at this point, the rooms still have Bob's
 descriptions), the very first line of actual code (third line in the
 program) is returning an error.

 Offending code:

 # Content
 # retrieve data for current room
 room == start
 while true:
 if room == start:
 desc = Ahead of you, you see a chasm.
 ques = Do you wish to try jumping over it? Y/N
 destY = 2
 destN = 3

 Error:

 Traceback (most recent call last):
   File samplegame.py, line 3, in module
 room == start
 NameError: name 'room' is not defined


 What's going on here?

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



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


Re: [Tutor] Finding the streaks in heads/tails list

2008-10-03 Thread nathan virgil
You need to store the count before resetting it since you want

 to know the largest value of count over the list. Or at least keep a
 separate max variable that you update if count  max.



Fairly easy:

if Cur_Count  Max_Count:
 Max_Count = Cur_Count

See? Just two extra lines of code.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread David
 Okay, I'm resurrecting this project.
Where is this project code?




-- 
Have Fun,
David A.

Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com

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


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread nathan virgil
On Fri, Oct 3, 2008 at 9:19 AM, David [EMAIL PROTECTED] wrote:

  Okay, I'm resurrecting this project.
 Where is this project code? http://www.linuxcrazy.com


Right here. The content is going to eventually go through some drastic
changes, but what's here should be good enough for testing.

# Content
# retrieve data for current room
room = 1
if room == 1:
desc = Ahead of you, you see a chasm.
ques = Do you wish to try jumping over it? Y/N
destYes = 2
destNo = 3
elif room == 2:
desc = Ahead of you, you see a warty green ogre.
ques = Do you wish to eat it? Y/N
destYes = 4
destNo = 5
# etc for the rest of the rooms

# Engine
# ask current question and move to next room
print desc
ans = raw_input(ques).upper() # allow for lower case input
if ans == Y:
room = destYes
elif ans == N:
room = destNo
elif ans == north:
room = destN
elif ans == south:
room = destS
elif ans == east:
room = destE
elif ans == west:
room = destW
elif ans == Q: # give us a way out.
Break
else:
print I don't understand. Can you give a clearer answer?


It seems like good code, but for some reason, it's not letting me go into
Room 2 (the ogre). I remember last time I tried this, the problem had
something to do with redirecting back into the same room, but I don't
remember exactly what that issue was.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread Luke Paireepinart
On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil [EMAIL PROTECTED] wrote:


 On Fri, Oct 3, 2008 at 9:19 AM, David [EMAIL PROTECTED] wrote:

  Okay, I'm resurrecting this project.
 Where is this project code?
 It seems like good code,
It's not.


 # Content
 # retrieve data for current room
 room = 1
 if room == 1:
this is always true because you just set room to 1 right before you
checked the variable.
 desc = Ahead of you, you see a chasm.
 ques = Do you wish to try jumping over it? Y/N
 destYes = 2
 destNo = 3
 elif room == 2:
this will never be true, which is why you can't get into the second room.
This whole thing needs to be in a loop.
But this is definitely not the best way to implement this either.

 desc = Ahead of you, you see a warty green ogre.
 ques = Do you wish to eat it? Y/N
 destYes = 4
 destNo = 5
 # etc for the rest of the rooms
He's wiring these rooms together with numbers.  The way I'd do it is
to create a Room object with a bunch of different methods, such as
room.print(), room.printDescription(), room.makeChoice(), and such,
and then the rooms would be connected together using data members.
It would be a lot more elegant and less confusing that way.


 # Engine
 # ask current question and move to next room
 print desc
 ans = raw_input(ques).upper() # allow for lower case input
 if ans == Y:
 room = destYes
 elif ans == N:
 room = destNo
 elif ans == north:
 room = destN
 elif ans == south:
 room = destS
 elif ans == east:
 room = destE
 elif ans == west:
 room = destW
 elif ans == Q: # give us a way out.
 Break
 else:
 print I don't understand. Can you give a clearer answer?

You prompted the user, then retrieved the next room value.
Now we're here, and there's no code left.  So it stops here.


but for some reason, it's not letting me go into
 Room 2 (the ogre).
Is it clearer why this isn't working now?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Daniele
 [Alec Henriksen]
  How trustworthy is the randomness generated by the random module?

 Python uses the Mersenne Twister algorithm for generating
 pseudo-random numbers, and that's one of the highest-quality methods
 known.

From here
http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
and here
http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

I think it can be argued that the randomness is pretty trustworthy :o)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread nathan virgil
On Fri, Oct 3, 2008 at 10:02 AM, Luke Paireepinart
[EMAIL PROTECTED]wrote:

 On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil [EMAIL PROTECTED]
 wrote:
 
 
  On Fri, Oct 3, 2008 at 9:19 AM, David [EMAIL PROTECTED] wrote:
 
   Okay, I'm resurrecting this project.
  Where is this project code?
  It seems like good code,
 It's not.


  # Content
  # retrieve data for current room
  room = 1
  if room == 1:
 this is always true because you just set room to 1 right before you
 checked the variable.
  desc = Ahead of you, you see a chasm.
  ques = Do you wish to try jumping over it? Y/N
  destYes = 2
  destNo = 3
  elif room == 2:
 this will never be true, which is why you can't get into the second room.
 This whole thing needs to be in a loop.
 But this is definitely not the best way to implement this either.

  desc = Ahead of you, you see a warty green ogre.
  ques = Do you wish to eat it? Y/N
  destYes = 4
  destNo = 5
  # etc for the rest of the rooms
 He's wiring these rooms together with numbers.  The way I'd do it is
 to create a Room object with a bunch of different methods, such as
 room.print(), room.printDescription(), room.makeChoice(), and such,
 and then the rooms would be connected together using data members.
 It would be a lot more elegant and less confusing that way.

 
  # Engine
  # ask current question and move to next room
  print desc
  ans = raw_input(ques).upper() # allow for lower case input
  if ans == Y:
  room = destYes
  elif ans == N:
  room = destNo
  elif ans == north:
  room = destN
  elif ans == south:
  room = destS
  elif ans == east:
  room = destE
  elif ans == west:
  room = destW
  elif ans == Q: # give us a way out.
  Break
  else:
  print I don't understand. Can you give a clearer answer?

 You prompted the user, then retrieved the next room value.
 Now we're here, and there's no code left.  So it stops here.

 
 but for some reason, it's not letting me go into
  Room 2 (the ogre).
 Is it clearer why this isn't working now?



Erm, no, not really. Are you saying I need to take out those last two lines?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread nathan virgil
On Fri, Oct 3, 2008 at 10:24 AM, nathan virgil [EMAIL PROTECTED]wrote:



 On Fri, Oct 3, 2008 at 10:02 AM, Luke Paireepinart [EMAIL PROTECTED]
  wrote:

 On Fri, Oct 3, 2008 at 8:50 AM, nathan virgil [EMAIL PROTECTED]
 wrote:
 
 
  On Fri, Oct 3, 2008 at 9:19 AM, David [EMAIL PROTECTED] wrote:
 
   Okay, I'm resurrecting this project.
  Where is this project code?
  It seems like good code,
 It's not.


  # Content
  # retrieve data for current room
  room = 1
  if room == 1:
 this is always true because you just set room to 1 right before you
 checked the variable.
  desc = Ahead of you, you see a chasm.
  ques = Do you wish to try jumping over it? Y/N
  destYes = 2
  destNo = 3
  elif room == 2:
 this will never be true, which is why you can't get into the second room.
 This whole thing needs to be in a loop.
 But this is definitely not the best way to implement this either.

  desc = Ahead of you, you see a warty green ogre.
  ques = Do you wish to eat it? Y/N
  destYes = 4
  destNo = 5
  # etc for the rest of the rooms
 He's wiring these rooms together with numbers.  The way I'd do it is
 to create a Room object with a bunch of different methods, such as
 room.print(), room.printDescription(), room.makeChoice(), and such,
 and then the rooms would be connected together using data members.
 It would be a lot more elegant and less confusing that way.

 
  # Engine
  # ask current question and move to next room
  print desc
  ans = raw_input(ques).upper() # allow for lower case input
  if ans == Y:
  room = destYes
  elif ans == N:
  room = destNo
  elif ans == north:
  room = destN
  elif ans == south:
  room = destS
  elif ans == east:
  room = destE
  elif ans == west:
  room = destW
  elif ans == Q: # give us a way out.
  Break
  else:
  print I don't understand. Can you give a clearer answer?

 You prompted the user, then retrieved the next room value.
 Now we're here, and there's no code left.  So it stops here.

 
 but for some reason, it's not letting me go into
  Room 2 (the ogre).
 Is it clearer why this isn't working now?



 Erm, no, not really. Are you saying I need to take out those last two
 lines?


Loops, then? The  code this is based off of  had the second line of  actual
code (between room = 1 and if room ==1) as while true:, but when I
include this, it gives an error at that line. Is there another way to do
that? Maybe while room != 4.2?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Andre Engels
On Fri, Oct 3, 2008 at 4:11 PM, Daniele [EMAIL PROTECTED] wrote:
 From here
 http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
 and here
 http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

 I think it can be argued that the randomness is pretty trustworthy :o)

Nice understatement on that last page - most applications do not
require 2^19937 unique combinations (2^19937 is approximately 4.315425
× 10^6001).

If you used every atom in the known universe as a computer, then let
them turn out a billion combinations a second for the entire time
since the big bang, and call the number of combination you get then
N...
then take N computers turning out N combinations a second for the
entire time since the big bang, and call the number of combinations
they turn out N2...
then take N2 computers turning out N2 combinations a second and call
the number of combination they turn out in the time since the big bang
and call that N3...
then the number of combinations turned out by N3 computers turning out
N3 combinations per second in the time since the big bang STILL
dwarves in comparison to that number.


-- 
André Engels, [EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Apress on sale at Bookpool

2008-10-03 Thread Kent Johnson
Bookpool.com is selling Apress titles at 50% off for December. Apress
has many good Python titles:

For learning Python:
- Beginning Python: From Novice to Professional, Second Edition
- Dive Into Python

Django:
- The Definitive Guide to Django: Web Development Done Right
- Practical Django Projects

Networking:
- Foundations of Python Network Programming

http://apress.com/book/catalog?category=144
http://www.bookpool.com/ct/272

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


Re: [Tutor] Apress on sale at Bookpool

2008-10-03 Thread Kent Johnson
Oops, that's October, not December!

On Fri, Oct 3, 2008 at 11:08 AM, Kent Johnson [EMAIL PROTECTED] wrote:
 Bookpool.com is selling Apress titles at 50% off for December. Apress
 has many good Python titles:

 For learning Python:
 - Beginning Python: From Novice to Professional, Second Edition
 - Dive Into Python

 Django:
 - The Definitive Guide to Django: Web Development Done Right
 - Practical Django Projects

 Networking:
 - Foundations of Python Network Programming

 http://apress.com/book/catalog?category=144
 http://www.bookpool.com/ct/272

 Kent

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


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Luke Paireepinart
Is your math correct?  That's ridiculously large.

On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels [EMAIL PROTECTED] wrote:
 On Fri, Oct 3, 2008 at 4:11 PM, Daniele [EMAIL PROTECTED] wrote:
 From here
 http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
 and here
 http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

 I think it can be argued that the randomness is pretty trustworthy :o)

 Nice understatement on that last page - most applications do not
 require 2^19937 unique combinations (2^19937 is approximately 4.315425
 × 10^6001).

 If you used every atom in the known universe as a computer, then let
 them turn out a billion combinations a second for the entire time
 since the big bang, and call the number of combination you get then
 N...
 then take N computers turning out N combinations a second for the
 entire time since the big bang, and call the number of combinations
 they turn out N2...
 then take N2 computers turning out N2 combinations a second and call
 the number of combination they turn out in the time since the big bang
 and call that N3...
 then the number of combinations turned out by N3 computers turning out
 N3 combinations per second in the time since the big bang STILL
 dwarves in comparison to that number.


 --
 André Engels, [EMAIL PROTECTED]
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Andre Engels
On Fri, Oct 3, 2008 at 5:25 PM, Luke Paireepinart
[EMAIL PROTECTED] wrote:
 Is your math correct?  That's ridiculously large.

1 year equals 3600 * 24 * 365 makes about 3*10^8 seconds.
The universe is about 15.000.000.000 years old, that's about 5*10^17 seconds.
With 1 billion combinations per second, each computer does 5*10^26
combinations in that time.
There are something like 10^70 or 10^72 particles in the universe,
thus N is about 10^100, give or take a factor of thousand or so.
N2 is equal to 5*10^17 * N * N, which we will round up to 10^220.
N3 by that same calculation will be about 10^460.
The unnamed last number that way becomes something like 10^940 (in
reality, because of all the rounding up, more like 10^930). That's
less than 1/10^600 of 10^1600 - I'd say that's dwarved by any
definition of the word.

 On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels [EMAIL PROTECTED] wrote:
 On Fri, Oct 3, 2008 at 4:11 PM, Daniele [EMAIL PROTECTED] wrote:
 From here
 http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
 and here
 http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

 I think it can be argued that the randomness is pretty trustworthy :o)

 Nice understatement on that last page - most applications do not
 require 2^19937 unique combinations (2^19937 is approximately 4.315425
 × 10^6001).

 If you used every atom in the known universe as a computer, then let
 them turn out a billion combinations a second for the entire time
 since the big bang, and call the number of combination you get then
 N...
 then take N computers turning out N combinations a second for the
 entire time since the big bang, and call the number of combinations
 they turn out N2...
 then take N2 computers turning out N2 combinations a second and call
 the number of combination they turn out in the time since the big bang
 and call that N3...
 then the number of combinations turned out by N3 computers turning out
 N3 combinations per second in the time since the big bang STILL
 dwarves in comparison to that number.


 --
 André Engels, [EMAIL PROTECTED]
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor





-- 
André Engels, [EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Andre Engels
On Fri, Oct 3, 2008 at 5:32 PM, Andre Engels [EMAIL PROTECTED] wrote:
 On Fri, Oct 3, 2008 at 5:25 PM, Luke Paireepinart
 [EMAIL PROTECTED] wrote:
 Is your math correct?  That's ridiculously large.

 1 year equals 3600 * 24 * 365 makes about 3*10^8 seconds.
 The universe is about 15.000.000.000 years old, that's about 5*10^17 seconds.
 With 1 billion combinations per second, each computer does 5*10^26
 combinations in that time.
 There are something like 10^70 or 10^72 particles in the universe,
 thus N is about 10^100, give or take a factor of thousand or so.
 N2 is equal to 5*10^17 * N * N, which we will round up to 10^220.
 N3 by that same calculation will be about 10^460.
 The unnamed last number that way becomes something like 10^940 (in
 reality, because of all the rounding up, more like 10^930). That's
 less than 1/10^600 of 10^1600 - I'd say that's dwarved by any
 definition of the word.

Oh, wait, I had to compare to 10^6001 instead of 10^1600... Which
means I could have gone on to N6 instead of N4.

 On Fri, Oct 3, 2008 at 10:03 AM, Andre Engels [EMAIL PROTECTED] wrote:
 On Fri, Oct 3, 2008 at 4:11 PM, Daniele [EMAIL PROTECTED] wrote:
 From here
 http://en.wikipedia.org/wiki/Pseudorandom_number_generator#Periodicity
 and here
 http://en.wikipedia.org/wiki/Mersenne_twister#Advantages

 I think it can be argued that the randomness is pretty trustworthy :o)

 Nice understatement on that last page - most applications do not
 require 2^19937 unique combinations (2^19937 is approximately 4.315425
 × 10^6001).

 If you used every atom in the known universe as a computer, then let
 them turn out a billion combinations a second for the entire time
 since the big bang, and call the number of combination you get then
 N...
 then take N computers turning out N combinations a second for the
 entire time since the big bang, and call the number of combinations
 they turn out N2...
 then take N2 computers turning out N2 combinations a second and call
 the number of combination they turn out in the time since the big bang
 and call that N3...
 then the number of combinations turned out by N3 computers turning out
 N3 combinations per second in the time since the big bang STILL
 dwarves in comparison to that number.


 --
 André Engels, [EMAIL PROTECTED]
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor





 --
 André Engels, [EMAIL PROTECTED]




-- 
André Engels, [EMAIL PROTECTED]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Daniele
2008/10/3 Andre Engels [EMAIL PROTECTED]:
 On Fri, Oct 3, 2008 at 4:11 PM, Daniele [EMAIL PROTECTED] wrote:
 If you used every atom in the known universe as a computer, then let
 them turn out a billion combinations a second for the entire time
 since the big bang, and call the number of combination you get then
 N [...].. then the number of combinations turned out by N3 computers turning 
 out
 N3 combinations per second in the time since the big bang STILL
 dwarves in comparison to that number.

Excellent Proof of concept! ,-)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-03 Thread Robert Berman






Andre Engels wrote:

  On Fri, Oct 3, 2008 at 5:25 PM, Luke Paireepinart
[EMAIL PROTECTED] wrote:
  
  
Is your math correct?  That's ridiculously large.

  
  
1 year equals 3600 * 24 * 365 makes about 3*10^8 seconds.
The universe is about 15.000.000.000 years old, that's about 5*10^17 seconds.
With 1 billion combinations per second, each computer does 5*10^26
combinations in that time.
There are something like 10^70 or 10^72 particles in the universe,
thus N is about 10^100, give or take a factor of thousand or so.
N2 is equal to 5*10^17 * N * N, which we will round up to 10^220.
N3 by that same calculation will be about 10^460.
The unnamed last number that way becomes something like 10^940 (in
reality, because of all the rounding up, more like 10^930). That's
less than 1/10^600 of 10^1600 - I'd say that's dwarved by any
definition of the word.


Wowee! Golleee! Gosh! That sure be some fine number crunching. 

Robert


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


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread Chris Babcock

 Loops, then? The  code this is based off of  had the second line of
 actual code (between room = 1 and if room ==1) as while true:,
 but when I include this, it gives an error at that line. Is there
 another way to do that? Maybe while room != 4.2?

What you had before was...

room = 1
if room == 1
  # Room 1 stuff
elif... #Stuff that never got executed
# End of program.


Try...

room = 1
while 1:
  if room == 1:
# Room 1 stuff
  elif room == 2:
# Room 2 stuff

Your switching variable can't be the loop control and you do need to be
in a loop for the conditional expression to be evaluated again after
you've changed the value of room.

Chris


-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] assigning values to dictionary

2008-10-03 Thread jeremiah
I have a list of dictionary values that i am looping through that upon
each iteration I would like to assign these values to a new dictionary
name. 

For example...

item=0
for line in some_dict:
## some how assign dict values to new name
new_dict_name_+item = line

I have not tested the example code above and is displayed simply for
demonstration purposes. 

Any thoughts on how to do this? 

Thanks,
JJ



Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.


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


Re: [Tutor] Hands-on beginner's project?

2008-10-03 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 09:38:56AM -0700, Chris Babcock wrote:
 room = 1
 while 1:

Also, it may be more clear to say while True: in preference
to while 1:.  Note that in your earlier version you didn't
capitalize True which meant Python had no idea what that
value was (could be a variable or something).  True and False
(and None, for that matter) are all capitalized.

   if room == 1:
 # Room 1 stuff
   elif room == 2:
 # Room 2 stuff

This is a good start while you're learning to program initially.
You'll later want to see how to generalize this so the collection
of rooms and connections between them exists in _data_ instead
of _code_.  Something to simmer on the back burner until you're
ready for that step.


-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] UnicodeEncodeError

2008-10-03 Thread Rob Sutherland
I'm working on a python application that stores email in a postgresql
database and
I'm encountering the UnicodeEncodeError - while storing a particular
email I receive
this error

UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
in position 144: character maps to undefined

I'm a little confused about a workaround for this, from what I've
googled the approach seems to be to use the codecs.register_error and
codecs.ignore_errors to skip processing of the offending character. I
haven't been able to find an understandable example though, so if
anyone has one that would be great.

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


Re: [Tutor] assigning values to dictionary

2008-10-03 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
 I have a list of dictionary values that i am looping through that upon
 each iteration I would like to assign these values to a new dictionary
 name. 
 
 For example...
 
 item=0
 for line in some_dict:
   ## some how assign dict values to new name
   new_dict_name_+item = line

You could use eval, I suppose, but are you sure that 
making up new dictionary names on the fly like that is
the solution that best fits the problem as opposed to
having, say, a set of objects or an overall dictionary
of dictionaries you add to?  What's the bigger context
this fits into?  Although you *can* do this sort of thing,
it quite often ends up not being the most elegant thing
to do.

-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning values to dictionary

2008-10-03 Thread jeremiah
i think i figured it out. The result is that I have a dictionary within
a dictionary..i think.

for example:

{'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}

How would I go about itterating through this?

Thanks,
JJ


On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
 On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
  I have a list of dictionary values that i am looping through that
 upon
  each iteration I would like to assign these values to a new
 dictionary
  name.
 
  For example...
 
  item=0
  for line in some_dict:
## some how assign dict values to new name
new_dict_name_+item = line
 
 You could use eval, I suppose, but are you sure that
 making up new dictionary names on the fly like that is
 the solution that best fits the problem as opposed to
 having, say, a set of objects or an overall dictionary
 of dictionaries you add to?  What's the bigger context
 this fits into?  Although you *can* do this sort of thing,
 it quite often ends up not being the most elegant thing
 to do.
 
 --
 Steve Willoughby|  Using billion-dollar satellites
 [EMAIL PROTECTED]   |  to hunt for Tupperware.
 
 
 


Disclaimer: The information contained in this transmission, including any 
attachments, may contain confidential information of Panasonic Avionics
Corporation.  This transmission is intended only for the use of the 
addressee(s) listed above.  Unauthorized review, dissemination or other use 
of the information contained in this transmission is strictly prohibited. 
If you have received this transmission in error or have reason to believe 
you are not authorized to receive it, please notify the sender by return 
email and promptly delete the transmission.


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


Re: [Tutor] assigning values to dictionary

2008-10-03 Thread W W
On Fri, Oct 3, 2008 at 1:02 PM, jeremiah [EMAIL PROTECTED]wrote:

 i think i figured it out. The result is that I have a dictionary within
 a dictionary..i think.

 for example:

 {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}

 How would I go about itterating through this?


for k, v in items(mydict):
for k, v in items(v):
   print k, v

I think that should work
hth,
Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning values to dictionary

2008-10-03 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 11:02:34AM -0700, jeremiah wrote:
 i think i figured it out. The result is that I have a dictionary within
 a dictionary..i think.
 
 for example:
 
 {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}
 
 How would I go about itterating through this?

Depends on how you want to iterate through it (what
in the end you're trying to accomplish).  One example:

for major_key in my_dict:
  print The stuff stored under, major_key, is:
  for minor_key in my_dict[major_key]:
print (%s) %s=%s % (major_key, minor_key, my_dict[major_key][minor_key])

Another possibility might be:

for major_key, subdict in my_dict.iteritems():
  print The stuff stored under, major_key, is:
  for minor_key, value in subdict.iteritems():
print (%s) %s=%s % (major_key, minor_key, value)


 
 Thanks,
 JJ
 
 
 On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
  On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
   I have a list of dictionary values that i am looping through that
  upon
   each iteration I would like to assign these values to a new
  dictionary
   name.
  
   For example...
  
   item=0
   for line in some_dict:
 ## some how assign dict values to new name
 new_dict_name_+item = line
  
  You could use eval, I suppose, but are you sure that
  making up new dictionary names on the fly like that is
  the solution that best fits the problem as opposed to
  having, say, a set of objects or an overall dictionary
  of dictionaries you add to?  What's the bigger context
  this fits into?  Although you *can* do this sort of thing,
  it quite often ends up not being the most elegant thing
  to do.
  
  --
  Steve Willoughby|  Using billion-dollar satellites
  [EMAIL PROTECTED]   |  to hunt for Tupperware.
  
  
  
 
 
 Disclaimer: The information contained in this transmission, including any 
 attachments, may contain confidential information of Panasonic Avionics
 Corporation.  This transmission is intended only for the use of the 
 addressee(s) listed above.  Unauthorized review, dissemination or other use 
 of the information contained in this transmission is strictly prohibited. 
 If you have received this transmission in error or have reason to believe 
 you are not authorized to receive it, please notify the sender by return 
 email and promptly delete the transmission.
 
 

-- 
Steve Willoughby|  Using billion-dollar satellites
[EMAIL PROTECTED]   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] assigning values to dictionary

2008-10-03 Thread jeremiah
Awesome. Thanks!

On Fri, 2008-10-03 at 11:07 -0700, Steve Willoughby wrote:
 On Fri, Oct 03, 2008 at 11:02:34AM -0700, jeremiah wrote:
  i think i figured it out. The result is that I have a dictionary
 within
  a dictionary..i think.
 
  for example:
 
  {'mcdonalds': {'hamburger': 'big mac','drink':'coke'}}
 
  How would I go about itterating through this?
 
 Depends on how you want to iterate through it (what
 in the end you're trying to accomplish).  One example:
 
 for major_key in my_dict:
   print The stuff stored under, major_key, is:
   for minor_key in my_dict[major_key]:
 print (%s) %s=%s % (major_key, minor_key,
 my_dict[major_key][minor_key])
 
 Another possibility might be:
 
 for major_key, subdict in my_dict.iteritems():
   print The stuff stored under, major_key, is:
   for minor_key, value in subdict.iteritems():
 print (%s) %s=%s % (major_key, minor_key, value)
 
 
 
  Thanks,
  JJ
 
 
  On Fri, 2008-10-03 at 10:39 -0700, Steve Willoughby wrote:
   On Fri, Oct 03, 2008 at 10:29:13AM -0700, jeremiah wrote:
I have a list of dictionary values that i am looping through
 that
   upon
each iteration I would like to assign these values to a new
   dictionary
name.
   
For example...
   
item=0
for line in some_dict:
  ## some how assign dict values to new name
  new_dict_name_+item = line
  
   You could use eval, I suppose, but are you sure that
   making up new dictionary names on the fly like that is
   the solution that best fits the problem as opposed to
   having, say, a set of objects or an overall dictionary
   of dictionaries you add to?  What's the bigger context
   this fits into?  Although you *can* do this sort of thing,
   it quite often ends up not being the most elegant thing
   to do.
  
   --
   Steve Willoughby|  Using billion-dollar satellites
   [EMAIL PROTECTED]   |  to hunt for Tupperware.
  
  
  
 
 
  Disclaimer: The information contained in this transmission,
 including any
  attachments, may contain confidential information of Panasonic
 Avionics
  Corporation.  This transmission is intended only for the use of the
  addressee(s) listed above.  Unauthorized review, dissemination or
 other use
  of the information contained in this transmission is strictly
 prohibited.
  If you have received this transmission in error or have reason to
 believe
  you are not authorized to receive it, please notify the sender by
 return
  email and promptly delete the transmission.
 
 
 
 --
 Steve Willoughby|  Using billion-dollar satellites
 [EMAIL PROTECTED]   |  to hunt for Tupperware.
 
 
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Coin Flip

2008-10-03 Thread realNewbie

This is a class assignment, I am to create a program that flips a coin 100
times and tells me the number of heads and tails.
I've been working on it for 2 days now and I am stuck. I a trying to run the
program but it is not running. 
Can someone please point out my error? 

Here is what I have come up with:
import random
heads=0
tails=0
count=1
while count 101:
   randomFlip = random.randrange(0,1)
if randomFlip == 0:
heads = heads + 1
else:
tails = tails + 1
count = count + 1
print heads, heads
print tails, tails
-- 
View this message in context: 
http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] UnicodeEncodeError

2008-10-03 Thread Kent Johnson
On Fri, Oct 3, 2008 at 1:50 PM, Rob Sutherland [EMAIL PROTECTED] wrote:
 I'm working on a python application that stores email in a postgresql
 database and
 I'm encountering the UnicodeEncodeError - while storing a particular
 email I receive
 this error

 UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
 in position 144: character maps to undefined

 I'm a little confused about a workaround for this, from what I've
 googled the approach seems to be to use the codecs.register_error and
 codecs.ignore_errors to skip processing of the offending character. I
 haven't been able to find an understandable example though, so if
 anyone has one that would be great.

It helps if you show the code that is causing the error and the full
traceback. Presumably you are calling someString.encode(some
encoding) where some encoding  is an encoding that doesn't include
the character U+2019 right single quotation mark
http://www.eki.ee/letter/chardata.cgi?ucode=2019

The string encode() method takes a second argument which indicates how
errors should be handled. See the docs for the options:
http://docs.python.org/library/stdtypes.html#str.encode

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


Re: [Tutor] Coin Flip

2008-10-03 Thread taserian
Since the variable *count* never increases inside of the loop body, it gets
stuck in the *while* loop.

I recommend taking a hard look at the program, consider what it should be
doing, and then seeing which statements should be in the *while* loop, and
which ones should be outside it.

Tony R.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie [EMAIL PROTECTED] wrote:


 This is a class assignment, I am to create a program that flips a coin 100
 times and tells me the number of heads and tails.
 I've been working on it for 2 days now and I am stuck. I a trying to run
 the
 program but it is not running.
 Can someone please point out my error?

 Here is what I have come up with:
 import random
 heads=0
 tails=0
 count=1
 while count 101:
   randomFlip = random.randrange(0,1)
 if randomFlip == 0:
heads = heads + 1
 else:
tails = tails + 1
 count = count + 1
 print heads, heads
 print tails, tails
 --
 View this message in context:
 http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
 Sent from the Python - tutor mailing list archive at Nabble.com.

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

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


Re: [Tutor] Coin Flip

2008-10-03 Thread bhaaluu
First off, check your program's indentation.

On Fri, Oct 3, 2008 at 2:04 PM, realNewbie [EMAIL PROTECTED] wrote:

 This is a class assignment, I am to create a program that flips a coin 100
 times and tells me the number of heads and tails.
 I've been working on it for 2 days now and I am stuck. I a trying to run the
 program but it is not running.
 Can someone please point out my error?

 Here is what I have come up with:
 import random
 heads=0
 tails=0
 count=1
 while count 101:
   randomFlip = random.randrange(0,1)
 if randomFlip == 0:
heads = heads + 1
 else:
tails = tails + 1
 count = count + 1
 print heads, heads
 print tails, tails
 --
 View this message in context: 
 http://www.nabble.com/Coin-Flip-tp19802888p19802888.html
 Sent from the Python - tutor mailing list archive at Nabble.com.

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




-- 
b h a a l u u at g m a i l dot c o m
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] UnicodeEncodeError

2008-10-03 Thread Kent Johnson
On Fri, Oct 3, 2008 at 2:39 PM, Rob Sutherland [EMAIL PROTECTED] wrote:
 On Fri, Oct 3, 2008 at 12:23 PM, Kent Johnson [EMAIL PROTECTED] wrote:

 It helps if you show the code that is causing the error and the full
 traceback. Presumably you are calling someString.encode(some
 encoding) where some encoding  is an encoding that doesn't i

 I'm encountering this error while attempting to store the string in
 a database, the code I execute is

 cur.execute(statement ,attachDict)

 which falls through to the code that actually does the encoding  in
 /usr/lib/python2.4/encodings/iso8859_1.py

 Traceback (most recent call last):
  File ./mail2db.py, line 219, in ?
storemail(cur, conn,emailDict,attachment_hold)
  File ./mail2db.py, line 118, in storemail
attachments_ok = 
 storeattachment(cur,conn,search_message_id,attachment_hold)
  File ./mail2db.py, line 61, in storeattachment
cur.execute(statement ,attachDict)
  File /usr/lib/python2.4/site-packages/psycopg2/extras.py, line 88,
 in execute
return _cursor.execute(self, query, vars, async)
  File /usr/lib/python2.4/encodings/iso8859_1.py, line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
 UnicodeEncodeError: 'charmap' codec can't encode character u'\u2019'
 in position 144: character maps to undefined

My guess is, your database is set up to hold ISO-8859-1 data
(Latin-1). You are giving it Unicode data, so it tries to encode as
Latin-1. The data includes a character that is not in Latin-1 so it
fails.

I would try explicitly converting the data to latin-1 before you send
it to the database, giving it one of the forgiving error handling
methods I referred to earlier. Or, change your database to UTF-8...

Kent

PS Please use Reply All to reply to the list.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] keep from opening multiple Toplevel windows

2008-10-03 Thread dwbarne
I have a Tkinter button widget that when pressed invokes a Toplevel window call 
each time. The Toplevel window thus generated has a close button on it. As you 
might guess, when multiple Toplevel windows are open, I can press on a 'close' 
button to '.destroy' the window, but all other Toplevel windows remain and do 
not respond to their 'close' buttons. I understand why THIS happens, but...

The behavior I seek is that one and only one Toplevel window gets generated no 
matter how many times the original Tkinter button is pressed. A new Toplevel is 
generated only after the previous one is closed.

My question is: how does one check that a particular Toplevel window is open? 
I've tried just checking on the Toplevel widget name with try-except, but the 
value of the Toplevel name stays persistent even when the .destroy method is 
used to kill the Toplevel window, which makes try-except think the Toplevel is 
still open. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor