~ Writing to file - registration screen in Python


Sample Project - Netflix type system

*Teachers with subscriptions will have access to all worked solutions and python code. This sample project is based on OCR GCSE NEA Task 1

CHALLENGE: 

Create a registration screen based on the set requirements. These should be stored to file. The file we will be using is called fakeflixfile.txt

SUGGESTED SOLUTION / CODE: 

Note: See if you can do better (and you should be able to). The solutions provided are basic, and allow for discussion on possible alternative methods and solutions.

#Netflix type system demo - FakeFlix
import csv
import sys

def main():
   menu()


def menu():
    print("************Welcome to FakeFlix Demo**************")
    print()

    choice = input("""
                      A: Please Register
                      B: Login
                      Q: Logout

                      Please enter your choice: """)

    if choice == "A" or choice =="a":
        register()
    elif choice == "B" or choice =="b":
        login()
    elif choice=="Q" or choice=="q":
        sys.exit
    else:
        print("You must only select either A or B")
        print("Please try again")
        menu()

def register():
  
    #user is prompted to input all the required fields
    print("Enter first name")
    firstname=input()
    print("Enter surname")
    surname=input()
    print("Enter Date of Birth Format: dd/mm/yy")
    dob=input()
    print("Enter first line of address")
    firstlineaddress=input()
    print("Enter Postcode")
    postcode=input()
    print("Enter Gender")
    gender=input()
    print("Enter main genre of interest")
    tutorgroup=input()
    print("Enter email address")
    email=input()
    substring=dob[-4:]
    print(substring)
    print("Your unique username is", firstname+surname+substring)
    username=firstname+surname+substring
    print("Please enter a password -it must contain a capital letter and at least one integer")
    password=input()    
    
    with open('fakeflixfile.txt','a') as fakeflixfile:
        fakeflixfileWriter=csv.writer(fakeflixfile)
        fakeflixfileWriter.writerow([username,password,firstname,surname,dob,firstlineaddress,postcode,gender,tutorgroup,email])
        print("Record has been written to file")
        fakeflixfile.close()
        menu()
        
    
def login():
   pass
    
#the program is initiated, so to speak, here
main()


Text File we've used:fakeflixfile.txt

username,password,test,user,dateofbirth,address,postcode,gender,interests,email
RM1979,Open@123,Ruth,Marvin,10/01/1979,144 CW Road,CR3 0FT,Female,Christian,[email protected]
PM2016,Carrots@123,pigachee,marvin,12/05/2016,Picachh Drive,CR3 CCC,Female,PIgness,[email protected]
JM1981,Mardod@123,Jonathan,Marvin,19/01/1981,5T Sweet Drive,R45 FF2,Male,Thriller,[email protected]
HannahPig2016,Open@123,Hannah,Pig,14/06/2016,Coon Drive,Cr3 44$,Female,Romance,[email protected]
MooseMouse2016,Moose@123#,Moose,Mouse,18/32/2016,Moose Close,MU89DFF,Male,Mooseyness,[email protected]
username13022,Username@123,user,name1,2/02/3022,user Road,US455P,Mle,Nothing,[email protected]
AugustineSalins1900.txt,Augstine@123,Augustine,Salins,5/02/1900,Hutchins Road,CRBBAAA,Male,Theology,[email protected]
JosieBletchway3333,Bb@123,Josie,Bletchway,29/02/3333,Bletch Park,BB44AA,Female,Encryption,[email protected]
JoeBloggs.0.0,Joe@Bloggs12,Joe,Bloggs,0.0.0.0,0 Road,00000,Male,Joe Blogs,[email protected]


Analyse

Write your own summary of the problem. What are your objectives? List the success criteria

Design Tools

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.

Try it yourself

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!