Demo entry 3963405



Submitted by anonymous on Mar 09, 2016 at 22:51
Language: Python 3. Code size: 1.4 kB.

# Anita Gannota
# 23/02/2016

#   Get  user input
#   PRINT it back to them with comma-separated strings
# UNTIL Quit

AllDone = False

while not AllDone:
    ListOfData = []
    UserIn = input("How old are you? What is your name? What is your job? ")
    WordList = UserIn.split()   # separate out the words into a list

    print("Words were:", WordList)   # display the words

    WordList = UserIn.split(", ")    # identify the separator
    print("Comma separated words were:", WordList)   # display the words


    # filename:
    MyFile = "SecondWriteFile.txt"

    # open file for write-overwrite:
    if ListOfData:   # list has 1+ items in it

        FileWriter = open(MyFile, "w")   # create file writing object

        for item in ListOfData:   # item by item from the list

            FileWriter.write("%s\n" %item)   # add the newline

            # get here when all items written...
        FileWriter.close()   # close the file

    else:   # catchall - no data to write

        print("No data to write")

    # quit now?
    Quit = input("Finished (Y/N): ")

    if Quit.lower()=="n":


for index in ListOfData:

    print (index[0])
    print (index[1])
    print (index[2])






This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).