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

2008-10-05 Thread Alan Gauld
"Omer" <[EMAIL PROTECTED]> wrote Here is the code: def main(): import string "import string" is unnecessary, mate. Not entirely true since the code uses string.split() However since the split method of the string could be used instead then that would indeed render the import unnecessa

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

2008-10-05 Thread Omer
On Fri, Oct 3, 2008 at 9:45 AM, David <[EMAIL PROTECTED]> wrote: > Here is the code: > > def main(): > import string > Hey, lagging a bit behind the list, "import string" is unnecessary, mate. ___ Tutor maillist - Tutor@python.org http://mail.pytho

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.

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

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

2008-10-02 Thread Alan Gauld
"David" <[EMAIL PROTECTED]> wrote Does that mean input() is obsolete (after all, Zelle's book is not the freshest on the shelf)? Or do they have different uses? They have different uses and input is very convenient at the >>> prompt or when experimenting but in most cases is the wrong choic

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

2008-10-02 Thread Alan Gauld
"David" <[EMAIL PROTECTED]> wrote However, I just found out that changing input() to raw_input() breaks my code: You want to know the average of the numbers: 1,2 Traceback (most recent call last): File "avgInput.py", line 13, in add = add + i TypeError: unsupported operand type(s) for +:

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

2008-10-02 Thread David
ROTECTED] 10/02/2008 02:06 PM To tutor@python.org, [EMAIL PROTECTED] cc Subject Re: [Tutor] dealing with user input whose value I don't know Cheers for the insights! However, I just found out that changing input() to raw_input() breaks my code: This pr

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

2008-10-02 Thread David
Hello Steve, thanks for all your help and comments. What happens, though, is that with numbers = int(raw_input("Please type the numbers, separated by commas: ")) my code is still defunct (whereas input() works): Please type the numbers, separated by commas: 1,2 Traceback (most recent call las

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

2008-10-02 Thread christopher . henk
y, you can have the users input the numbers one at a time inside the loop. add = add + int(raw_input("Please type the next number:")) Chris David <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 10/02/2008 02:06 PM To tutor@python.org, [EMAIL PROTECTED] cc Subject Re: [Tuto

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

2008-10-02 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 02:06:47AM +0800, David wrote: > Cheers for the insights! > > However, I just found out that changing input() to raw_input() breaks my > code: Recall that we told you raw_input() returns a string, while input() returns an integer if you typed an integer value. So you nee

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

2008-10-02 Thread Steve Willoughby
On Thu, Oct 02, 2008 at 10:54:56AM -0700, Bill Campbell wrote: > Remember the cardinal rule NEVER TRUST USER INPUT! Always check > for validity, and use methods that prevent malicious strings from > allowing the user to get unauthorized access or change things > they shouldn't. Yes, I probably sh

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

2008-10-02 Thread David
Cheers for the insights! However, I just found out that changing input() to raw_input() breaks my code: This program takes the average of numbers you supply!! How many numbers do you want me to work with? 2 You want me to take the average of 2 numbers. Please type the numbers, separated by com

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

2008-10-02 Thread Bill Campbell
On Thu, Oct 02, 2008, Steve Willoughby wrote: >On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote: >> Does that mean input() is obsolete (after all, Zelle's book is not the >> freshest on the shelf)? Or do they have different uses? > >Depends on how you look at it. > >input() automatically eval

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

2008-10-02 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 01:38:48AM +0800, David wrote: > Does that mean input() is obsolete (after all, Zelle's book is not the > freshest on the shelf)? Or do they have different uses? Depends on how you look at it. input() automatically evaluates whatever the user types as a Python expression

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

2008-10-02 Thread David
Hello Christopher, [EMAIL PROTECTED] wrote: > > Okay, I can ask how many number are to be added: > > numbers = input("How many number do you want me to calculate? ") you should really use raw_input to get the info from the user, and then convert it to a number. numbers=int

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

2008-10-02 Thread christopher . henk
[EMAIL PROTECTED] wrote on 10/02/2008 01:06:29 PM: > Hello, > > I am trying to do some exercises in John Zelle's book (chapter 4). > I got stuck: > > "Write a program that finds the average of a series of numbers entered > by the user. The program should first ask the user how many numbers >

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

2008-10-02 Thread Steve Willoughby
On Fri, Oct 03, 2008 at 01:06:29AM +0800, David wrote: > Hello, > > I am trying to do some exercises in John Zelle's book (chapter 4). > I got stuck: > > Okay, I can ask how many number are to be added: > > numbers = input("How many number do you want me to calculate? ") > > If I then get a rep

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

2008-10-02 Thread Luke Paireepinart
On Thu, Oct 2, 2008 at 12:06 PM, David <[EMAIL PROTECTED]> wrote: > Hello, > > I am trying to do some exercises in John Zelle's book (chapter 4). > I got stuck: > > "Write a program that finds the average of a series of numbers entered by > the user. The program should first ask the user how many n

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

2008-10-02 Thread David
Hello, I am trying to do some exercises in John Zelle's book (chapter 4). I got stuck: "Write a program that finds the average of a series of numbers entered by the user. The program should first ask the user how many numbers there are. Note: the average should always be a float, even if the u