-3

I want this program to be in a loop until the user puts DONE

import datetime


fileName =input('file name :')
fileName = fileName+'.csv'
access ='w'
currentdate=datetime.date.today()

with open (fileName,access)as newFile :
    newFile.write('Name,Age,Nationality,Date\n')
    while True:
        name=input('Name:')
        age=input('Age: ' )
        nationality=input('Nationality: ')     
        newFile.write(name+','+age+','+nationality+',%s'%currentdate+'\n')
        if name or age or nationality == 'DONE':
            break
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

In the following IF statement in your code, nationality is the only variable being compared to the string value 'NONE'.

if name or age or nationality == 'DONE':
    break

Try either of the following

if any(x == 'DONE' for x in [name, age, nationality]):
    break

if 'DONE' in [name, age, nationality]:
    break
Christopher Nuccio
  • 596
  • 1
  • 9
  • 21