NEED HELP- read file contents, while loop to accept user input, and enter to exit

Chris Angelico rosuav at gmail.com
Tue May 24 04:46:32 EDT 2011


On Tue, May 24, 2011 at 6:31 PM, Cathy James <nambo4jb at gmail.com> wrote:
>     s = input ('enter name: ').strip()

Are you using Python 2 or Python 3? If it's Python 2, this should be
raw_input().

>     f = open ('c:/testing.txt', 'a')
> ...
>         f = open ('c:/testing.txt', 'r')

You may be having trouble here as a result of not closing the file and
then trying to reopen it.

Also, at some point you have to check if 's' (the user's inputted
string) is empty. You can then leave the loop using the 'break'
statement.

Hope that helps! Best of luck with your homework.

Chris Angelico



More information about the Python-list mailing list