Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views11 pages

Danlin Zhang

Uploaded by

qiao lin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

Danlin Zhang

Uploaded by

qiao lin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Centre Name: The Liverpool Blue Coat School Centre Number: 34425

Task completed: Song Task


Date started Date completed
1/12/2020 8/2/2022

Analysis
Try and create 3 or more key success criteria for your program.

Success Criteria:
1. Allows a player to enter their details, which are then authenticated to ensure that they are an
authorised player.
a. Input from user
b. Checks whether username and password are correct
c. Compare with data in CSV file
2. Stores a list of song names and artists in an external file.
a. Saves songs in a CSV file
b. Songs and artists are listed in a way that is easy to read
3. Selects a song from the file, displaying the artist and the first letter of each word of the song
title.
a. Selects random song from the file
b. Display’s the artist’s name
c. Display only first letter of song title
4. Allows the user up to two chances to guess the name of the song, stopping the game if they
guess a song incorrectly on the second chance.
a. Count number of guesses taken
b. Stop game if two guesses made and both incorrect
c.
5. If the guess is correct, add the points to the player’s score depending on the number of
guesses.
6. Displays the number of points the player has when the game ends.
7. Stores the name of the player and their score in an external file.

Design
 You may like to create a flow charts which will show broadly how your program will work. If so
include your flow chart in this section.

Candidate Name:
Candidate Number:
Date:
Version 1 1 © OCR 2018
Centre Name: The Liverpool Blue Coat School Centre Number: 34425

 You must create pseudocode for a part of your program (minimum of 15 lines). If possible, try
to create all of your program in pseudocode. Use the OCR guide in the specification to help
you.

import CSV

import random

with open("song_list.csv") as csvfile:

contentcsv= csv.reader(csvfile,delimiter=",")

songs=[]

for data in contentcsv:

songs.append(data)

ENDFOR

score <- 0

FUNCTION sign_in():

global username

data <- list(csv.reader(open("login.csv")))

username <- input("enter username:")

password <- input("enter password:")

user_pass <- [username,password]

IF user_pass in data:

OUTPUT "username AND password found"

ENDIF

game()

ENDFUNCTION

FUNCTION login():

datafile=open("login.csv","r")

Candidate Name:
Candidate Number:
Date:
Version 1 2 © OCR 2018
Centre Name: The Liverpool Blue Coat School Centre Number: 34425

login=[]

for line in datafile:

linedata=line.split(",")

login.append(linedata)

linedata[1]=linedata[1].strip()

ENDFOR

user=input("enter username")

for item in login:

IF user = item [0]:

OUTPUT "username found"

password <- input("enter password")

IF password = item [1]:

OUTPUT ("welcome")

break

ELSEIF user != item[0] AND password != [1]:

OUTPUT ("user AND pass dont match")

login()

ENDIF

ENDIF

ENDFUNCTION

ENDFOR

FUNCTION game():

count <- 0

while count <10:

Candidate Name:
Candidate Number:
Date:
Version 1 3 © OCR 2018
Centre Name: The Liverpool Blue Coat School Centre Number: 34425

x <- random.choice(songs)

OUTPUT (x[2],'by',x[1])

guess=0

while guess<3:

user=input("enter guess")

IF user.lower()== x[0].lower():

OUTPUT ("correct")

game()

ELSEIF user.lower()!= x[0].lower():

OUTPUT ("incorrect")

guess+=1

ELSEIF user = input("stop"):

break

ENDIF

ENDWHILE

count+=1

ENDFUNCTION

ENDWHILE

sign_in(),game()

Candidate Name:
Candidate Number:
Date:
Version 1 4 © OCR 2018
Centre Name: Centre Number:

Test design
 Think of tests that you can carry out to see if your system works

 Remember to try and use normal, boundary and erroneous tests.

 If you wish to, you may add more tests to the table.

My tests:

Test What am I testing? What data will I use? Normal/Boundary/Erroneous? Expected Result
1 Login function Username ‘danlin’ Normal ‘Username and password found’
Password ‘1234’
2 User input for song Location by Khalid Normal ‘correct’
guessing
3 Whether only first Press enter to display Normal First letter of song and artist printed
letter of song prints song and artist
4 Incorrect guess dfrgdhg Erroneous ‘incorrect’
5 Incorrect username Username: ‘sdfdsg’ Erroneous ‘username and password not found’
and password
Password: ‘fdrgfd’

Candidate Name:
Candidate Number:
Date:
Version 1 5 © OCR 2018
Centre Name: Centre Number:

Development
 Copy and paste your code into this section

 Remember to try and add comments to your code to make it more readable!

My program code:

import csv

import random

with open("song_list.csv") as csvfile:

contentcsv= csv.reader(csvfile,delimiter=",")

songs=[]

for data in contentcsv:

songs.append(data)

score = 0

def sign_in():

global username

data = list(csv.reader(open("login.csv")))

username = input("enter username:")

password = input("enter password:")

user_pass = [username,password]

if user_pass in data:

print("username and password found")

game()

def login():
Candidate Name:
Candidate Number:
Date:
Version 1 6 © OCR 2018
Centre Name: Centre Number:

datafile=open("login.csv","r")

login=[]

for line in datafile:

linedata=line.split(",")

login.append(linedata)

linedata[1]=linedata[1].strip()

user=input("enter username")

for item in login:

if user == item [0]:

print("username found")

password = input("enter password")

if password == item [1]:

print ("welcome")

break

elif user != item[0] and password != [1]:

print ("user and pass dont match")

login()

def game():

count = 0

while count <10:

x = random.choice(songs)

print (x[2],'by',x[1])

Candidate Name:
Candidate Number:
Date:
Version 1 7 © OCR 2018
Centre Name: Centre Number:

guess=0

while guess<3:

user=input("enter guess")

if user.lower()== x[0].lower():

print ("correct")

game()

elif user.lower()!= x[0].lower():

print ("incorrect")

guess+=1

elif user == input("stop"):

break

count+=1

sign_in(),game()

Candidate Name:
Candidate Number:
Date:
Version 1 8 © OCR 2018
Centre Name: Centre Number:

Testing
 Show you have completed the tests you thought of

 Identify if you needed to make changes to your program

 Include the screenshots of the tests

My tests:

Do I need to change my program?


Test What am I testing? Expected result Pass/Fail
If so, how?
1 Login function ‘Username and Pass
password found’
2 User input for song ‘correct’ Pass
guessing
3 Whether only first First letter of song and Pass
letter of song prints artist printed
4 Incorrect guess ‘incorrect’ Pass
5 Incorrect username ‘username and Pass
and password password not found’

My test screenshots:

Candidate Name:
Candidate Number:
Date:
Version 1 9 © OCR 2018
Centre Name: Centre Number:

Candidate Name:
Candidate Number:
Date:
Version 1 10 © OCR 2018
Centre Name: Centre Number:

Evaluation
 Evaluate how successful your program was. You should like your evaluation to your testing
results.

 You should reflect on any new skills you have developed

This section should be approximately 200-500 words.

How successful was my program?

My program was quite successful. The code I wrote did what was intended and fulfilled the
success criteria. There were a few errors as I was writing my code, but through testing I
identified these errors straight away and corrected them. The organisation of my code helped
me create this program with ease, ensuring my variables names weren’t confusing or hard to
understand.

What new skills have I developed?

I have developed my problem-solving skills through finding errors in my code and fixing
them. I also developed organisation, keeping my code organised and using appropriate
variables to make it easier to use, such as ‘guess’. These variable names made it easier to
work throughout my code and helped me focus on writing it rather than trying to work out my
variables. I also developed my resilience, working to correct parts of my code despite finding
some of it difficult.

Candidate Name:
Candidate Number:
Date:
Version 1 11 © OCR 2018

You might also like