The Student Room Group

Urgent help required.

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.
What specifically are you struggling with?
Reply 2
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.
What language are you using?
Reply 4
Original post by Afrrcyn
What language are you using?

Python
Reply 5
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. :smile:
## 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(winnerdetails)
winnerscorecsv.close()
print('Winner\'s score has been updated on to the external file')
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. :smile:
## 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(winnerdetails)
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:
Reply 7
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 ?🤔
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.

Quick Reply

Latest

Trending

Trending