raw_input that able to do detect multiple input

Dave Angel davea at davea.name
Sun Apr 7 01:25:47 EDT 2013


(You forgot to separate the parts of my comments that you were quoting 
from your responses.  Any decent email program will do that for you 
automatically, inserting "< " in front of each quoted line.  Then you 
just hit enter a couple of times to type the new stuff right after the 
part you're quoting.)


On 04/07/2013 01:00 AM, Frank wrote:
> Now you've saved the data in a different file.  How does the next run of
> the program find it?
>
>
> What user?  In what environment can a user enter function calls into
> your code?
> -The user will call the function out from IDLE

So the user is the programmer.  No end-user would be using IDLE to run a 
program.

>
> Why is the command invalid?
> -Because the user need to type out a name after the "f"

But that wouldn't be an invalid command, but invalid data

>
> That's not the way the message is worded in the code
> - because if user type in " a John Cleese, Cheese Shop, 5552233, 5 May"
> it mean it would takes four arguments (comma separated) with information
> about a person and adds that person to my "friends.csv". An error message is printed if that person is already a friend. Because the name "John Cleese" is already in my friends.csv that why it will prompt out "John Cleese is already a friend"

So fix the code, I just pointed out that the message was different.  The 
code says  print "%s is already in the list" % name

Yet you say the message needs to be:
 > John Cleese is already a friend

One or the other is incorrect.

>
> In this function and in save_friends, there is no return value, so not
> clear what you mean by  'result'
>
> e ends the interaction and, if the friends information has been
> updated, the information is saved to the friends.csv , i think i used the wrong function for this.

No, just the wrong filename.  I assumed you were going to rename it 
afterwards, tut apparently not.

>
> The question I'm told to work on:
> interact() is the top-level function that de
nes the text-base user interface
> as described in the introduction.
>

So if you call interact() in your program at the top-level, then a 
non-programmer can run the program directly from the terminal window.

> Here is an example of what is expected from your program. The input is
> everything after Command: on a line (and the initial friends.csv). Every-
> thing else is output. Your output should be exactly the same as below for
> the given input.
>
> interact()
> Friends File: friends.csv
> Command: f John Cleese
> John Cleese: Ministry of Silly Walks, 5555421, 27 October
> Command: f Michael Palin
> Unknown friend Michael Palin
> Command: f
> Invalid Command: f
> Command: a Michael Palin
> Invalid Command: a Michael Palin
> Command: a John Cleese, Cheese Shop, 5552233, 5 May
> John Cleese is already a friend
> Command: a Michael Palin, Cheese Shop, 5552233, 5 May
> Command: f Michael Palin
> Michael Palin: Cheese Shop, 5552233, 5 May
> Command: e
> Saving changes...
> Exiting...
>

You will also need to add an argument to the raw_input() to have it 
produce the output specified.


-- 
DaveA



More information about the Python-list mailing list