Demo entry 3972515

AnitaGannota

   

Submitted by anonymous on Mar 10, 2016 at 11:24
Language: Python 3. Code size: 1.6 kB.

# Anita Gannota
# 23/02/2016

# REPEAT
#   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

    ListOfData.append(WordList)

    # 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":

        AllDone=True


for index in ListOfData:

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





##if ListOfData:
##    for item in ListOfData:
##        Fields= item.split(", ")
##        print ("%s" %Fields[0])
##    
##    
##else:
##    print ("")


  

            














        
    








    

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).