usernamr
Badges: 11
Rep:
?
#1
Report Thread starter 3 months ago
#1
Hi there. I am struggling with my nom exam assessment for gcse computer science. The exam board is aqa (flight cost program). Could anyone help ?

Thanks.
0
reply
Afrrcyn
Badges: 18
Rep:
?
#2
Report 3 months ago
#2
What specifically are you struggling with?
0
reply
usernamr
Badges: 11
Rep:
?
#3
Report Thread starter 3 months ago
#3
(Original post by Afrrcyn)
What specifically are you struggling with?
I am struggling with reading text from a csv file and taking information from the csv file and implementing it into my code. We have not been taught this in class after having 4 teachers in 2 years.
0
reply
Afrrcyn
Badges: 18
Rep:
?
#4
Report 3 months ago
#4
What language are you using?
0
reply
usernamr
Badges: 11
Rep:
?
#5
Report Thread starter 3 months ago
#5
(Original post by Afrrcyn)
What language are you using?
Python
0
reply
a109
Badges: 11
Rep:
?
#6
Report 3 months ago
#6
Hey, this is my OCR GCSE python programming project you can find the csv file in there if u want copy the code in to python and see how it works then u will understand how it works.
Hope this helps.
## IMPORT RANDOM AND TIME AND CSV ##

import random
import time
import csv

i = 0
Player1Points = 0
Player2Points = 0
Player1Tiebreaker = 0
Player2Tiebreaker = 0
Winner_Points = 0

## LOGGING IN TO THE GAME ##
print("This is a two-player dice game.")
account = input('Player one do you already have an account')
access = False
if account == 'yes':
csvfile = open('users.csv')
reader = csv.reader(csvfile)
username = input('Enter your username')
password = input('Enter your password')
for row in reader:
if row[2]==username:
if row[3]==password:
print("You have been logged in to your account")
access = True
user1=username
if access == False:
print("The username and password is incorrect")
exit()
else:
newaccountquestion = input("Would you like to make a new account")
if newaccountquestion == 'yes':
firstname = input('Enter your first name')
lastname = input ('Enter your last name')
username = input('Enter your username')
password = input('Enter a secure password')
number = False
capital = False
lower = False
for a in password:
if a.isupper() == True:
capital = True
elif a.islower() == True:
lower = True
elif a.isnumeric() == True:
number = True
if capital == False or lower == False or number == False:
print("The password that you have entered is not secure enough, try again")
else:
csvfile = open('users.csv','a')
newaccount = '\n'+ firstname +','+ lastname +','+ username + ',' + password
csvfile.write(newaccount)
csvfile.close()
print("Your new account has been created")
else:
print("Ok, if you want a new account start again")
exit()
account = input('Player two do you already have an account')
access = False
if account == 'yes':
csvfile = open('users.csv')
reader = csv.reader(csvfile)
username = input('Enter your username')
password = input('Enter your password')
for row in reader:
if row[2]==username:
if row[3]==password:
print("You have been logged in to your account")
access = True
user2= username
if access == False:
print("The username and password is incorrect")
exit()
else:
newaccountquestion = input("Would you like to make a new account")
if newaccountquestion == 'yes':
firstname = input('Enter your first name')
lastname = input ('Enter your last name')
username = input('Enter your username')
password = input('Enter a secure password')
number = False
capital = False
lower = False
for a in password:
if a.isupper() == True:
capital = True
elif a.islower() == True:
lower = True
elif a.isnumeric() == True:
number = True
if capital == False or lower == False or number == False:
print("The password that you have entered is not secure enough, try again")
else:
csvfile = open('users.csv','a')
newaccount = '\n'+ firstname +','+ lastname +','+ username + ',' + password
csvfile.write(newaccount)
csvfile.close()
print("Your new account has been created")
else:
print("Ok, if you want a new account start again")
exit()
print("Both players are now logged in\n These are the rules of the game:\n The two players roll two 6-sided dice each and get points depending on what they roll.\n There are 5 rounds in a game.\n In each round, each player rolls the two dice.")



##ROLLING DICE##


def roll():

points = 0

die1 = random.randint(1,6)

die2 = random.randint(1,6)

dietotal = die1 + die2

points = points + dietotal

points != -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25

if dietotal % 2 == 0:
points = points + 10

else:
points = points - 5

if die1 == die2:
die3 = random.randint(1,6)
points = points +die3

return(points)

##

for i in range(1,5):
Player1Points += roll()
print('Total points for this round for ',user1, 'is ',Player1Points,' Points')
time.sleep(1)
Player2Points += roll()
print('Total points for this round for ',user2, 'is ',Player2Points,' Points')
time.sleep(1)

if Player1Points == Player2Points:
while Player1Tiebreaker == Player2Tiebreaker:


Player1Tiebreaker = random.randint(1,6)
Player2Tiebreaker = random.randint(1,6)

if Player1Tiebreaker > Player2Tiebreaker:
Player2Points = 0
elif Player2Tiebreaker > Player1Tiebreaker:
Player1Points = 0

##WINNER##

if Player1Points>Player2Points:
Winner_Points = Player1Points
winner_User = user1
winner = (Winner_Points, user1)
elif Player2Points>Player1Points:
Winner_Points = Player2Points
winner = (Winner_Points, user2)
winner_User = user2

print('Well done, ', winner_User,' you won with ',Winner_Points,' Points')

##SCORES UPLOADED TO EXTERNAL FILE

winnerscorecsv = open('winnerscore.csv','a')
winnerdetails = '\n' + str(Winner_Points) +','+ str(winner_User)
winnerscorecsv.write(winnerdetai ls)
winnerscorecsv.close()
print('Winner\'s score has been updated on to the external file')
0
reply
Afrrcyn
Badges: 18
Rep:
?
#7
Report 3 months ago
#7
Okay.
I haven't used Python is ages, but the general idea is you're gonna want to read each line within the file and seperate the data with commas and then read that into a data structure, a list in python's case.

Nice Website I found
Another one


The general idea is you want to:

Readline()
for each line, split(",") the data and store in a list.

(Original post by a109)
Hey, this is my OCR GCSE python programming project you can find the csv file in there if u want copy the code in to python and see how it works then u will understand how it works.
Hope this helps.
## IMPORT RANDOM AND TIME AND CSV ##

import random
import time
import csv

i = 0
Player1Points = 0
Player2Points = 0
Player1Tiebreaker = 0
Player2Tiebreaker = 0
Winner_Points = 0

## LOGGING IN TO THE GAME ##
print("This is a two-player dice game.")
account = input('Player one do you already have an account')
access = False
if account == 'yes':
csvfile = open('users.csv')
reader = csv.reader(csvfile)
username = input('Enter your username')
password = input('Enter your password')
for row in reader:
if row[2]==username:
if row[3]==password:
print("You have been logged in to your account")
access = True
user1=username
if access == False:
print("The username and password is incorrect")
exit()
else:
newaccountquestion = input("Would you like to make a new account")
if newaccountquestion == 'yes':
firstname = input('Enter your first name')
lastname = input ('Enter your last name')
username = input('Enter your username')
password = input('Enter a secure password')
number = False
capital = False
lower = False
for a in password:
if a.isupper() == True:
capital = True
elif a.islower() == True:
lower = True
elif a.isnumeric() == True:
number = True
if capital == False or lower == False or number == False:
print("The password that you have entered is not secure enough, try again")
else:
csvfile = open('users.csv','a')
newaccount = '\n'+ firstname +','+ lastname +','+ username + ',' + password
csvfile.write(newaccount)
csvfile.close()
print("Your new account has been created")
else:
print("Ok, if you want a new account start again")
exit()
account = input('Player two do you already have an account')
access = False
if account == 'yes':
csvfile = open('users.csv')
reader = csv.reader(csvfile)
username = input('Enter your username')
password = input('Enter your password')
for row in reader:
if row[2]==username:
if row[3]==password:
print("You have been logged in to your account")
access = True
user2= username
if access == False:
print("The username and password is incorrect")
exit()
else:
newaccountquestion = input("Would you like to make a new account")
if newaccountquestion == 'yes':
firstname = input('Enter your first name')
lastname = input ('Enter your last name')
username = input('Enter your username')
password = input('Enter a secure password')
number = False
capital = False
lower = False
for a in password:
if a.isupper() == True:
capital = True
elif a.islower() == True:
lower = True
elif a.isnumeric() == True:
number = True
if capital == False or lower == False or number == False:
print("The password that you have entered is not secure enough, try again")
else:
csvfile = open('users.csv','a')
newaccount = '\n'+ firstname +','+ lastname +','+ username + ',' + password
csvfile.write(newaccount)
csvfile.close()
print("Your new account has been created")
else:
print("Ok, if you want a new account start again")
exit()
print("Both players are now logged in\n These are the rules of the game:\n The two players roll two 6-sided dice each and get points depending on what they roll.\n There are 5 rounds in a game.\n In each round, each player rolls the two dice.")



##ROLLING DICE##


def roll():

points = 0

die1 = random.randint(1,6)

die2 = random.randint(1,6)

dietotal = die1 + die2

points = points + dietotal

points != -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18,-19,-20,-21,-22,-23,-24,-25

if dietotal % 2 == 0:
points = points + 10

else:
points = points - 5

if die1 == die2:
die3 = random.randint(1,6)
points = points +die3

return(points)

##

for i in range(1,5):
Player1Points += roll()
print('Total points for this round for ',user1, 'is ',Player1Points,' Points')
time.sleep(1)
Player2Points += roll()
print('Total points for this round for ',user2, 'is ',Player2Points,' Points')
time.sleep(1)

if Player1Points == Player2Points:
while Player1Tiebreaker == Player2Tiebreaker:


Player1Tiebreaker = random.randint(1,6)
Player2Tiebreaker = random.randint(1,6)

if Player1Tiebreaker > Player2Tiebreaker:
Player2Points = 0
elif Player2Tiebreaker > Player1Tiebreaker:
Player1Points = 0

##WINNER##

if Player1Points>Player2Points:
Winner_Points = Player1Points
winner_User = user1
winner = (Winner_Points, user1)
elif Player2Points>Player1Points:
Winner_Points = Player2Points
winner = (Winner_Points, user2)
winner_User = user2

print('Well done, ', winner_User,' you won with ',Winner_Points,' Points')

##SCORES UPLOADED TO EXTERNAL FILE

winnerscorecsv = open('winnerscore.csv','a')
winnerdetails = '\n' + str(Winner_Points) +','+ str(winner_User)
winnerscorecsv.write(winnerdetai ls)
winnerscorecsv.close()
print('Winner\'s score has been updated on to the external file')
This ruins the fun of solving the problem on their own :rolleyes:
1
reply
usernamr
Badges: 11
Rep:
?
#8
Report Thread starter 3 months ago
#8
(Original post by Afrrcyn)
Okay.
I haven't used Python is ages, but the general idea is you're gonna want to read each line within the file and seperate the data with commas and then read that into a data structure, a list in python's case.

Nice Website I found
Another one


The general idea is you want to:

Readline()
for each line, split(",") the data and store in a list.

This ruins the fun of solving the problem on their own :rolleyes:

Thanks I sort of understand now . Do you have any idea where I can get the full code for the aqa flight cost task ?🤔
0
reply
Afrrcyn
Badges: 18
Rep:
?
#9
Report 3 months ago
#9
(Original post by usernamr)
Thanks I sort of understand now . Do you have any idea where I can get the full code for the aqa flight cost task ?🤔
No idea mate, there's not one specific way to solve these sorts of problems. I didn't even finish my NEA at GCSE, I just had a good go, I don't know how AQA marks these and if they need to be completed.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

What factors affect your mental health the most right now?

Anxiousness about lockdown easing (95)
5.01%
Uncertainty around my education (287)
15.14%
Uncertainty around my future career prospects (201)
10.6%
Lack of purpose or motivation (266)
14.03%
Lack of support system (eg. teachers, counsellors, delays in care) (83)
4.38%
Impact of lockdown on physical health (109)
5.75%
Loneliness (164)
8.65%
Financial worries (68)
3.59%
Concern about myself or my loves ones getting/having been ill (83)
4.38%
Exposure to negative news/social media (90)
4.75%
Lack of real life entertainment (105)
5.54%
Lack of confidence in making big life decisions (166)
8.76%
Worry about missed opportunities during the pandemic (179)
9.44%

Watched Threads

View All