Re: [Tutor] range() help

2007-04-17 Thread Necmettin Begiter
On Tuesday 17 April 2007 14:42:50 [EMAIL PROTECTED] wrote:
> >>> range(-10, -100, -30)
>
> [-10, -40, -70]
>
> How come it prints on -40 or -70.
>
> Does -70 come from -70 -> -100?
>
from -10 to -100 (excluding -100)
-10-30 = -40
-40-30= -70
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sys.argv?

2007-04-17 Thread Jan Erik Moström
Reply to [EMAIL PROTECTED] 07-04-17 07:26:

>I've been reading the python tutorial trying to get used to the style
>tryna understand it.  So I come across this: "sys.argv[0]" in the tutorial
>on python.org.  What is "sys.argv"?  How does it work? Can someone give me
>a simple example on how to use it?

It's how you read the argument from the command line


Example, a simple script

import sys

for x in sys.argv:
 print "Argument: ", x

and then how you can us it

>python ex.py
Argument:  ex.py
>python ex.py hello
Argument:  ex.py
Argument:  hello
>python ex.py hello world
Argument:  ex.py
Argument:  hello
Argument:  world
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sys.argv?

2007-04-17 Thread python
I've been reading the python tutorial trying to get used to the style
tryna understand it.  So I come across this: "sys.argv[0]" in the tutorial
on python.org.  What is "sys.argv"?  How does it work? Can someone give me
a simple example on how to use it?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Trouble with "RuntimeError: underlying C/C++ object has been deleted".

2007-04-17 Thread Lawrence Shafer

Hello List,

I am just learning Python/PyQt4, and have a problem I cannot figure out.
Here's what happens.

Traceback (most recent call last):
  File "iac.py", line 124, in on_actionOpen_triggered
self.open()
  File "iac.py", line 66, in open
if self.isUntitled and self.textBrowser.document().isEmpty() and not
self.isWindowModified():
RuntimeError: underlying C/C++ object has been deleted


I have copied several parts of other programs, so that's probably where
this is coming from. All I want is to load a .txt file into
self.textBrowser, so some of the functionality is unneeded at this time,
except for filter saving and loading. If someone understands what is
going on, that would be great!

Files are attached.

Thanks!
Lawrence



iac.py
Description: application/python


filterEdit_ui.py
Description: application/python


iac_ui.py
Description: application/python
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Error in my code

2007-04-17 Thread govind goyal

Hi,

I am executing following lines of code:

def WEP40_KEY(n):
 params = urllib.urlencode({})
 headers = {"Connection": "Keep-Alive","Authorization": ""}
 conn = httplib.HTTPConnection(HOST)
 conn.request("GET", "/w_sec.htm HTTP/1.1", params, headers)
   response = conn.getresponse()
   print response.status, response.reason
params = 
urllib.urlencode({'wsecurity':"WEP",'wep_auth':"Shared+Key",'wepenc':"128+bit",'wep_key_no':"key1",'ascii_key1':"12345678901234567890123456",'ascii_key2':"",'ascii_key3':"",'ascii_key4':"",'passphrase':"",'wpa_psk':"12345678",'key_lifetime':"65535",'wpa_enc':"TKIP",'save':"Save",'message':
"",'todo':""})
   headers = {"Connection": "Keep-Alive","Authorization": ""}
   conn = httplib.HTTPConnection(HOST)
   conn.request("POST", "w_sec.htm", params, headers)
   response = conn.getresponse()
   print response.status, response.reason
   conn.close()

WEP40_KEY(sys.argv)



I am getting following error:


C:\Documents and Settings\Govindadya\Desktop\Marvell>Marvell_WEP40.py
192.168.1.
16
 File "C:\Documents and
Settings\Govindadya\Desktop\Marvell\Marvell_WEP40.py",
line 41
  * response = conn.getresponse()
   ^
IndentationError: unindent does not match any outer indentation level*

**

Can anybody help me out on this?

Best Regards,

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


Re: [Tutor] 'word jumble' game

2007-04-17 Thread Jason Massey

The main thing your program lacks is flexibility.  Adding new puzzles
requires chaining together a series of if..else statements and creating
variables for each hint.

Here's my quick version.  I store the puzzles and the hints in a two-tuple
sequence.  Following this method you could easily add additional hints for
each puzzle.

(I changed up the scoring system a bit too...just my spin on it)

import random

# create a series of puzzles to choose from
puzzles = (("python","It's the best programming language for the absolute
beginner ..."),
  ("jumble","It's what this program does to words to make it
difficult to guess them ..."),
  ("easy","It's not difficult ..."),
  ("difficult","It's not easy ..."),
  ("answer","It's not a question ..."),
  ("xylophone","It's a musical instrument you have to hit with 2
small sticks ..."))


# pick one word randomly from the sequence
which_puzzle = random.choice(range(len(puzzles)))
correct_word = puzzles[which_puzzle][0]
jumbled_word = list(correct_word)
hint = puzzles[which_puzzle][1]

random.shuffle(jumbled_word)
jumbled_word = ''.join(jumbled_word)

print \
"""
   Welcome to Word Jumple!

   Unscramble the letters to make a word.
   (Press the enter key at the prompt to quit.)
"""


score = 0
while 1:
   print "The jumble:", jumbled_word
   guess = raw_input("\nYour guess: ")
   guess = guess.lower()

   if guess == '':
   break

   if guess != correct_word:
   print "Sorry that's not it."
   hint_prompt = raw_input("Would you like a hint? Y/N: ")
   hint_prompt = hint_prompt.lower()
   if hint_prompt.startswith('y'):
   print hint+"\n"
   score -= 50

   if guess == correct_word:
   score += 200
   print "\nThat's it! You guessed it!\n"
   if score == 200:
   print "Because you never asked for a hint you get %d points.\n"
% (score)
   else:
   print "Since you asked for a hint or two you're score is %d
points.\n" % (score)
   break


print "\nThanks for playing."


On 4/17/07, Alexander Kapshuk <[EMAIL PROTECTED]> wrote:


 Hello Everyone,



This is Alexander Kapshuk writing here again …



Could you please have a look at the code below and let me know of any
shortcuts that could be used there.



The code works fine as it is. I was just wandering if there was a better,
more compact and elegant way of writing the program.



Thanking you all in advance.



Alexander Kapshuk





# Word Jumble Game

#

# The computer picks a random word and then "jumbles" it.

# The player has to guess the original word.

#

# Should the player be stuck and require a hint, they will be prompted for
a hint.

# If the player answers 'yes', the appropriate hint will be displayed and
the player will be asked to guess again.

# If the player answers 'no', they will be asked to guess again and
awarded some points if they manage to guess the jumbled word without ever
asking for a hint.



import random



# create a sequence of words to choose from

WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")



# pick one word randomly from the sequence

word = random.choice(WORDS)



# create a variable to use later to see if the guess is correct

correct = word



# create hints for all the jumbled words

hint0 = "\nIt's the best programming language for the absolute beginner
...\n"

hint1 = "\nIt's what this program does to words to make it difficult to
guess them ...\n"

hint2 = "\nIt's not difficult ...\n"

hint3 = "\nIt's not easy ...\n"

hint4 = "\nIt's not a question ...\n"

hint5 = "\nIt's a musical instrument you have to hit with 2 small sticks
...\n"



# create a jumbled version of the word

jumble = ""



while word:

position = random.randrange(len(word))

jumble += word[position]

word = word[:position] + word[(position + 1):]



# start the game

print \

"""

Welcome to Word Jumple!



Unscramble the letters to make a word.

(Press the enter key at the prompt to quit.)

"""

print "The jumble:", jumble



guess = raw_input("\nYour guess: ")

guess = guess.lower()

score = 0

while (guess != correct) and (guess != ""):

print "\nSorry, that's not it.\n"

hint_prompt = raw_input("Would you like a hint? Y/N: ")

hint_prompt = hint_prompt.lower()

if hint_prompt == "yes" and correct == WORDS[0]:

print hint0

elif hint_prompt == "yes" and correct == WORDS[1]:

print hint1

elif hint_prompt == "yes" and correct == WORDS[2]:

print hint2

elif hint_prompt == "yes" and correct == WORDS[3]:

print hint3

elif hint_prompt == "yes" and correct == WORDS[4]:

print hint4

elif hint_prompt == "yes" and correct == WORDS[5]:

print hint5

elif hint_prompt == "no":

score += 50



guess = raw_input("Your guess: ")

guess = guess.lower()



if guess == correct and hint_prompt == "no":

print "\nThat's it! Yo

Re: [Tutor] sys.argv?

2007-04-17 Thread Rikard Bosnjakovic
On 4/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I've been reading the python tutorial trying to get used to the style
> tryna understand it.  So I come across this: "sys.argv[0]" in the tutorial
> on python.org.  What is "sys.argv"?  How does it work? Can someone give me
> a simple example on how to use it?

sys.argv is a list containing all the arguments sent to the program at
invokation. The name "argv" is derived from the C-world; argument
values.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error in my code

2007-04-17 Thread Mike Hansen
If what you posted is exactly what your code looks like, then you've got
an indentation problem. Since Python doesn't use {}'s for code blocks,
it uses indentation instead, and it's somewhat picky about indentation.

I think all the code after the first conn.request should line up with
the conn.request.

def WEP40_KEY(n):
  params = urllib.urlencode({})
  headers = {"Connection": "Keep-Alive","Authorization": ""}
  conn = httplib.HTTPConnection(HOST)
  conn.request ("GET", "/w_sec.htm HTTP/1.1", params, headers)
  response = conn.getresponse()
  print response.status, response.reason
  params =
urllib.urlencode({'wsecurity':"WEP",'wep_auth':"Shared+Key",'wepenc':"12
8+bit",'wep_key_no':"key1",'ascii_key1':"12345678901234567890123456",'as
cii_key2':"",'ascii_key3':"",'ascii_key4':"",'passphrase':"",'wpa_psk':"
12345678",'key_lifetime':"65535",'wpa_enc':"TKIP",'save':"Save",'message
': "",'todo':""}) 
  headers = {"Connection": "Keep-Alive","Authorization": ""}
  conn = httplib.HTTPConnection(HOST)
  conn.request("POST", "w_sec.htm", params, headers) 
  response = conn.getresponse()
  print response.status, response.reason
  conn.close() 

It looks like your indenting 2 spaces. I believe the recommendation is 4
spaces. You might read the style guide.

http://www.python.org/doc/essays/styleguide.html

Out of curiosity, what editor are you using to write your code? You can
configure many editors to automatically indent for you, change tabs to
spaces, and set tabs to 4 spaces.

Mike

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of govind goyal
> Sent: Tuesday, April 17, 2007 9:29 AM
> To: tutor@python.org
> Subject: [Tutor] Error in my code
> 
> Hi,
>  
> I am executing following lines of code:
>  
> def WEP40_KEY(n):
>   params = urllib.urlencode({})
>   headers = {"Connection": "Keep-Alive","Authorization": ""}
>   conn = httplib.HTTPConnection(HOST)
>   conn.request ("GET", "/w_sec.htm HTTP/1.1", params, headers)
> response = conn.getresponse()
> print response.status, response.reason
>  params = 
> urllib.urlencode({'wsecurity':"WEP",'wep_auth':"Shared+Key",'w
> epenc':"128+bit",'wep_key_no':"key1",'ascii_key1':"12345678901
234567890123456",'ascii_key2':"",'ascii_key3':"",'ascii_key4':"",'passph
rase':"",'wpa_psk':"1234567>
8",'key_lifetime':"65535",'wpa_enc':"TKIP",'save':"Save",'mess
> age': "",'todo':""}) 
> headers = {"Connection": "Keep-Alive","Authorization": ""}
> conn = httplib.HTTPConnection(HOST)
> conn.request("POST", "w_sec.htm", params, headers) 
> response = conn.getresponse()
> print response.status, response.reason
> conn.close()
> 
> WEP40_KEY(sys.argv)
>  
>  
>  
> I am getting following error:
>  
> 
> C:\Documents and 
> Settings\Govindadya\Desktop\Marvell>Marvell_WEP40.py 192.168.1.
> 16
>   File "C:\Documents and 
> Settings\Govindadya\Desktop\Marvell\Marvell_WEP40.py",
> line 41
> response = conn.getresponse()
> ^
> IndentationError: unindent does not match any outer indentation level
> 
>  
> 
> Can anybody help me out on this?
> 
> Best Regards,
> 
> Govind
> 
>  
> 
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 'word jumble' game

2007-04-17 Thread Alexander Kapshuk
Hello Everyone,

 

This is Alexander Kapshuk writing here again ...

 

Could you please have a look at the code below and let me know of any
shortcuts that could be used there.

 

The code works fine as it is. I was just wandering if there was a
better, more compact and elegant way of writing the program.

 

Thanking you all in advance.

 

Alexander Kapshuk

 

 

# Word Jumble Game

#

# The computer picks a random word and then "jumbles" it.

# The player has to guess the original word.

#

# Should the player be stuck and require a hint, they will be prompted
for a hint.

# If the player answers 'yes', the appropriate hint will be displayed
and the player will be asked to guess again.

# If the player answers 'no', they will be asked to guess again and
awarded some points if they manage to guess the jumbled word without
ever asking for a hint.

 

import random

 

# create a sequence of words to choose from

WORDS = ("python", "jumble", "easy", "difficult", "answer", "xylophone")

 

# pick one word randomly from the sequence

word = random.choice(WORDS)

 

# create a variable to use later to see if the guess is correct

correct = word

 

# create hints for all the jumbled words

hint0 = "\nIt's the best programming language for the absolute beginner
...\n"

hint1 = "\nIt's what this program does to words to make it difficult to
guess them ...\n"

hint2 = "\nIt's not difficult ...\n"

hint3 = "\nIt's not easy ...\n"

hint4 = "\nIt's not a question ...\n"

hint5 = "\nIt's a musical instrument you have to hit with 2 small sticks
...\n"

 

# create a jumbled version of the word

jumble = ""

 

while word:

position = random.randrange(len(word))

jumble += word[position]

word = word[:position] + word[(position + 1):]

 

# start the game

print \

"""

Welcome to Word Jumple!

 

Unscramble the letters to make a word.

(Press the enter key at the prompt to quit.)

"""

print "The jumble:", jumble

 

guess = raw_input("\nYour guess: ")

guess = guess.lower()

score = 0

while (guess != correct) and (guess != ""):

print "\nSorry, that's not it.\n"

hint_prompt = raw_input("Would you like a hint? Y/N: ")

hint_prompt = hint_prompt.lower()

if hint_prompt == "yes" and correct == WORDS[0]:

print hint0

elif hint_prompt == "yes" and correct == WORDS[1]:

print hint1

elif hint_prompt == "yes" and correct == WORDS[2]:

print hint2

elif hint_prompt == "yes" and correct == WORDS[3]:

print hint3

elif hint_prompt == "yes" and correct == WORDS[4]:

print hint4

elif hint_prompt == "yes" and correct == WORDS[5]:

print hint5

elif hint_prompt == "no":

score += 50



guess = raw_input("Your guess: ")

guess = guess.lower()

 

if guess == correct and hint_prompt == "no":

print "\nThat's it! You guessed it!\n"

print "Because you never asked for a hint you get", score,
"points.\n"

 

print "\nThanks for playing."

 

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



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


[Tutor] range() help

2007-04-17 Thread python
Alright I'm a bit confused when looking at how range works.  I'm reading
lesson 4.3 in the python tutorial. http://docs.python.org/tut/node6.html

I came across this:

>>> range(-10, -100, -30)
[-10, -40, -70]

How come it prints on -40 or -70.

Does -70 come from -70 -> -100?

This is really confusing me.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] range() help

2007-04-17 Thread Jan Erik Moström
Reply to [EMAIL PROTECTED] 07-04-17 07:42:

>How come it prints on -40 or -70.
>
>Does -70 come from -70 -> -100?
>
>This is really confusing me.

I don't really understand your question, the definition of range

range(...)
 range([start,] stop[, step]) -> list of integers

 Return a list containing an arithmetic progression of integers.
 range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) 
defaults to 0.
 When step is given, it specifies the increment (or decrement).
 For example, range(4) returns [0, 1, 2, 3].  The end point 
is omitted!
 These are exactly the valid indices for a list of 4 elements.

So you are basically telling python to start from -10, and then 
subtract -30 until it reaches -100.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sys.argv?

2007-04-17 Thread Rikard Bosnjakovic
On 4/17/07, Kirk Bailey <[EMAIL PROTECTED]> wrote:

> IF my memory serves well, argument 0 in that list is the name of the
> program itself, as well as the path to it if any was provided.

Stop replying to my mailbox.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Learning Python in cooperative, challenging way.

2007-04-17 Thread Giulio 'Mac' Maistrelli
Hello everybody,

I hope this is the right place to make this question. If not I would 
appreciate
help in getting pointed towards a different resource...

I just began to learn python. It is a nice language to learn, and I am 
using
"dive into python" which is also a nicely written book... yet I am missing a lot
two aspects in this learning experience:

1) The co-operation / interaction with other learners (and/or teachers).
2) The challenge

To clarify point #2: Python - as any learning - IS challenging, but as I am
learning it "just for fun" and without any real need to fulfil, I don't have any
"operational challenge", if that makes any sense in English... :-/

So far the best I could find has been: #1 --> this mailing list #2 -->
http://www.pythonchallenge.com

Any more suggestions from your side?

Thank you very much in advance,
Mac.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sys.argv?

2007-04-17 Thread Luke Paireepinart
Rikard Bosnjakovic wrote:
> On 4/17/07, Kirk Bailey <[EMAIL PROTECTED]> wrote:
>
>   
>> IF my memory serves well, argument 0 in that list is the name of the
>> program itself, as well as the path to it if any was provided.
>> 
>
> Stop replying to my mailbox.
>   
I really wish this list would start mungin' some headers already.

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


[Tutor] Python Browser based?

2007-04-17 Thread python
How can I used python online.  I'm getting my hoster to install python and
I'm wondering how Do I use python online?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Browser based?

2007-04-17 Thread Bob Gailer
[EMAIL PROTECTED] wrote:
> How can I used python online.  I'm getting my hoster to install python and
> I'm wondering how Do I use python online?
>   
Could you be more specific?

-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] Python Browser based?

2007-04-17 Thread Teresa Stanton
I would like more information about this as well.  I found something on
sourceforge about using python modules to run a web cam.  I've got the
files, but not quite sure how to use the web server.

 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of [EMAIL PROTECTED]
Sent: Tuesday, April 17, 2007 2:03 PM
To: tutor@python.org
Subject: [Tutor] Python Browser based?

How can I used python online.  I'm getting my hoster to install python and
I'm wondering how Do I use python online?
___
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] Python for CGI (was Python Browser based?)

2007-04-17 Thread Bob Gailer
Regarding using Python for CGI - Googling "python cgi" reveals many 
potentially useful links. These sound

http://www.cs.virginia.edu/~lab2q/
www.python.org/doc/essays/ppt/sd99east/sld038.htm

-- 
Bob Gailer
510-978-4454

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


Re: [Tutor] Learning Python in cooperative, challenging way.

2007-04-17 Thread Mike Hansen
 

> -Original Message-
> 
> To clarify point #2: Python - as any learning - IS 
> challenging, but as I am
> learning it "just for fun" and without any real need to 
> fulfil, I don't have any
> "operational challenge", if that makes any sense in English... :-/
> 
> So far the best I could find has been: #1 --> this mailing list #2 -->
> http://www.pythonchallenge.com
> 
> Any more suggestions from your side?
> 
> Thank you very much in advance,
> Mac.

You look at some of the ideas at this page.

http://effbot.org/pyfaq/tutor-im-learning-python-what-should-i-program.h
tm

or http://tinyurl.com/yalvar

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


[Tutor] Empty Range for RandRange

2007-04-17 Thread Ellen Kidda

Would someone kindly review the following code and error?  This sample
program is copied from Python Programming for the Absolute Beginner (2nd
ed.)  I'm running Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32
bit (Intel)] on win32.  (Python 2.3 is the version referenced in this
edition.)  Referenced lines 8 and 9 of the error are the 3rd and 2nd lines
from the last in the code.  Thank you very much.
Ellen

#Demonstrates string indexing

import  random

word = "index"

print "The word is: ", word, "\n"

high = len(word)

low = len(word)

for i in range(10):

   position = randrange(low, high)

   print "word[", position, "]\t", word[position]

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


line 8, in -toplevel-position = random.randrange(low, high)  #line 9 error:
"empty range for randrange"
 File "C:\Python23\lib\random.py", line 178, in randrange
   raise ValueError, "empty range for randrange()"
ValueError: empty range for randrange()
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Empty Range for RandRange

2007-04-17 Thread Kent Johnson
Ellen Kidda wrote:
> Would someone kindly review the following code and error?  This sample 
> program is copied from Python Programming for the Absolute Beginner (2nd 
> ed.)  I'm running Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 
> 32 bit (Intel)] on win32.  (Python 2.3 is the version referenced in this 
> edition.)  Referenced lines 8 and 9 of the error are the 3rd and 2nd 
> lines from the last in the code.  Thank you very much.
> Ellen
> 
> #Demonstrates string indexing
> 
> import  random
> 
> word = "index"
> 
> print "The word is: ", word, "\n"
> 
> high = len(word) 
> 
> low = len(word)  

Notice that low and high are the same.
> 
> for i in range(10):
> 
> position = randrange(low, high)

This picks from the range low <= number < high. Since low == high the 
range is empty.

Kent

> 
> print "word[", position, "]\t", word[position]
> 
> raw_input("\n\nPress the enter key to exit.")
> 
> 
> 
> line 8, in -toplevel-position = random.randrange(low, high)  #line 9 
> error:  "empty range for randrange"
>   File "C:\Python23\lib\random.py", line 178, in randrange
> raise ValueError, "empty range for randrange()"
> ValueError: empty range for randrange()
> 
> 
> 
> 
> 
> ___
> 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] Python Browser based?

2007-04-17 Thread Hugo González Monteverde
Hi,

Do you want to:

1) use Python from a website or server without installing it in a computer?

2) use Python to do things with the Internet or servers, website, etc?

Hugo

[EMAIL PROTECTED] wrote:
> How can I used python online.  I'm getting my hoster to install python and
> I'm wondering how Do I use python online?
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tuto
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] celcius to farenheit converter.

2007-04-17 Thread python
I found this site and I'm practicing coding and I write this script, but
I'm unsure why its not working.  Everything goes well until it gets to the
part where it tries to calculate the formula.  Inputs work fine anyone
know what I did wrong?

###
#Temperature Converter
#Coding Practice for lamonte(uni-code.com)
###

temp = raw_input("Insert a temperature to convert.\n")

type = raw_input("Now choose a convertion: Celcius(c) or Farenheit(f)")

if type == "c":
cel = (5/9)*(temp-32)
print "Farhrenheit" +temp+" is equal to "+cel+" celcius.\n"
elif type == "f":
far = (9/5)*(temp+32)
print "Farhrenheit" +far+" is equal to "+temp+" celcius.\n"
else:
print "Unknown Syntax!\n";

raw_input("\nPress enter to close program")
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sys.argv?

2007-04-17 Thread Rikard Bosnjakovic
On 4/17/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote:

> I really wish this list would start mungin' some headers already.

I second that.

Not using a reply-to-tag is braindead.


-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] celcius to farenheit converter.

2007-04-17 Thread Rikard Bosnjakovic
On 4/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

> I found this site and I'm practicing coding and I write this script, but
> I'm unsure why its not working.  Everything goes well until it gets to the
> part where it tries to calculate the formula.  Inputs work fine anyone
> know what I did wrong?

In the future, please add what error message you get. That saves us
some type cutting and pasting the code, and running it.

The thing that's wrong with your code is that you try to multiply an
integer with a string. raw_input() returns a string, not an integer.
What you want to do is to convert it to an int first:

temp = raw_input("Insert a temperature to convert.\n")
temp_int = int(temp)

Also, print cannot mix ints and strings using string concatenation
(+). What you want to do is to use string formats.

So, the final code would be something like this:

temp = raw_input("Insert a temperature to convert.\n")
temp_int = int(temp)

type = raw_input("Now choose a convertion: Celcius(c) or Farenheit(f)")

if type == "c":
   cel = (5/9)*(temp_int-32)
   print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, cel)
elif type == "f":
   far = (9/5)*(temp+32)
   print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, far)
else:
   print "Unknown Syntax!\n";

raw_input("\nPress enter to close program")



-- 
- Rikard - http://bos.hack.org/cv/
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] celcius to farenheit converter.

2007-04-17 Thread Luke Paireepinart
Rikard Bosnjakovic wrote:
> On 4/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>   
>> I found this site and I'm practicing coding and I write this script, but
>> I'm unsure why its not working.  Everything goes well until it gets to the
>> part where it tries to calculate the formula.  Inputs work fine anyone
>> know what I did wrong?
>> 
>
> if type == "c":
>cel = (5/9)*(temp_int-32)
>   
a side-note:
5/9 is 0 in Python 2.5 and earlier.
'/' defaults to integer division if both sides are integers as well.
What you'd want to do is 5.0/9  or 5/9.0 or 5.0/9.0 or just 0.5
same applies to your 9/5 below.
>print "Farhrenheit %d is equal to %d celcius.\n" % (temp_int, cel)
> elif type == "f":
>far = (9/5)*(temp+32)

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