Hi all. I'm making a program about 'reading and writing text files'
The assignment I have to do is suppose to look like this: http://i39.tinypic.com/5554wi.jpg

But I can't figure it how to make it so when it keeps looping until the user types in 'break' and it will list the names entered.

help, or brief explaination please? thank you!

blank=""
while not blank:
    blank=("Enter your name or break to exit:")

y = open("pa16names.txt", "w")
x = raw_input("Enter your name or break to exit:")
y.writelines(x)
y. close()  

y = open ("pa16names.txt", "r")
print "The names you've entered into the text file are:", y.read()
y.close()

Recommended Answers

All 2 Replies

I was trying this out and I didn't get it to work yet either, but it seems like you could use a

while x != 'break':

and maybe an append(x) somewhere to help from writing over the previously entered names. I'll keep working on it.

Put the proper code inside the loop and it will work ...

fout = open("pa16names.txt", "w")

while True:
    name = raw_input("Enter your name (just Enter to exit): ")
    fout.writelines(name + '\n')
    if name == "":
        break

fout. close()

print
fin = open ("pa16names.txt", "r")
print "The names you've entered into the text file are:"
print fin.read()
fin.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.