~ Add users to a file in Python - python made easy


Add a new user to a file in Python - this involves writing to the file

Challenge -Add a new user to the file (write a full user's record to the file)

Read the task instructions that are included in the comments in the code, and then get started!

You can either edit and code online in repl.it or alternatively, you can simply cut and paste the below into your own python file

Solve the challenge on repl.it

Code

""" ==============TASK
What if we want to ADD a new user to fakefacebook?! We would need to WRITE (and not read) from file

1.Add the required user input to add an entire full record to the file. (e.g. id, firstname, lastname, username, password, no.of.friends,etc.)
2. Write this record to the file, as has been shown with the example below
"""

import csv

#1. This code snippet asks the user to enter an ID number and first name, and writes it to the file (appends)

with open('fakefacebook_write.txt','a',newline="") as fo: #open the file in append mode (add to file, we don't wish to overwrite!)
        Writer=csv.writer(fo) #fo = file out (this can be called anything you like)
        id=input("Enter ID:")
        firstname=input("Enter firstname:")
        Writer.writerow([id,firstname])
        print("Record has been written to file")

File Contents

Filename:fakefacebook_write

ID,firstname, lastname,username,password,email,no_of_likes
001,Ruth,Marvin,marvR,pass123,[email protected],400
002,Carter,Smith,smithC,open123,[email protected],200
003,Joe,Blogs, blogsJ,2bg123,[email protected],99
004,Ruth,Pigachee,pigR,pig123,[email protected],72


Code your solution here

Systems Life Cycle (in a nutshell): Analyse - Design - Create - Test - Evaluate. Designing something or writing out some pseudocode before you actually write code is always a good idea! Get in to the habit of doing so! You can draw your flowchart here and screenshot it.

A sample flow chart (design) for this particular challenge could look like:

Flowchart: Python program to get the Fibonacci series between 0 to 50
Each challenge section below provides an online drawing tool where you can dynamically create flowcharts. Screenshot them into your presentation for submission.

Solutions & Answers

Answers /Solutions in the "members area" drive under: "Solve and Learn >>SOLUTIONS"

Testing Table

You may want to read a little about Testing first. A teacher may go through some examples with you. Feel free to fill in the test table here, and screenshot it in to your powerpoint. Testing is absolutely essential once you have created a program!
Test No. Description Test Data(input) Expected Outcome Actual Outcome Further Action?
1
2
3
4
5
Coming soon!