Friday, 29 November 2019

# 45 SAVING DATA in a csv DOC

#45 My Zoo. #SAVING DATA in a csv DOC

animals = []
while True:
    print ('Name of animals you have. Type FFF to finish')
    newname=input()
    animals.append(newname)
    animals.sort()
    print (animals)
 
    if newname == 'FFF':
        animals.remove(newname)
        print ()
        print ('This is your list: ')
        animals.sort()
        print (animals)
        break

print()
print ('Need to add more?')
YESNO = input()
if YESNO =='yes':
    while True:
        print ('Name of animals you want to add. Type XXX to finish')
        newname=input()
        animals.append(newname)
        animals.sort()
        print (animals)
     
 
        if newname == 'XXX':
            animals.remove(newname)
            print ()
            print ('This is your list: ')
            animals.sort()
            print (animals)
            break

elif YESNO == 'no':
    print (animals)
    print ('Thank you.')

print ()
print ('Need to delete any?')
YESNO2 = input()
if YESNO2 =='yes':
    while True:
        print ('Name of animals you want to remove. Type XXX to finish')
        removeName=input()
        if removeName != 'XXX':
            animals.remove(removeName)
            animals.sort()
            print (animals)
 
        elif removeName == 'XXX':
            print ('This is your list: ')
            animals.sort()
            print (animals)
            break
     

elif YESNO2 == 'no':
    animals.sort()
    print (animals)
    print ('Thank you. Let´s save now the data')
    print()

################################################################
#SAVING DATA in a csv DOC
import csv

print ('Name the csv document remember to finish with: .csv')
csvDOC = input()

with open(csvDOC, 'w') as csv_file:
    csv_writer = csv.writer(csv_file, delimiter=',')
    csv_writer.writerow(animals)