I don't know how but it seems that my ages keep getting mixed up within the while loop. It also doesn't include one of the names. The loop works within the IDE but I can't get it to write correctly into the text file.
def main():
friendsfile = open('friends.txt', 'w')
name = str(input('Enter first name of friend or Enter to quit : '))
while name != '':
age = int(input('Enter age of this friend : '))
name = str(input('Enter first name of friend or Enter to quit : '))
friendsfile.write(name + '\n')
friendsfile.write(str(age) + '\n')
friendsfile.close()
print('File was created')
main()
When I enter the names Justin with age 13, Scott with age 20, and Lucy with age 14 I get this written to the file.
Scott 13 Lucy 20
14