My Computer Science Exam PreRelease (Off Topic)

Sort:
Avatar of SpeedyCyclone

Hey. happy.png

I Just wanted to share my Computer Science Exam PreRelease Task that I just finished. It is quite long and is about Sorting Money for a School Trip and I want to know what do you all think. Thanks for stopping by! tongue.png

#constant values
coachCost = 550
costOfTicket = 30
maxStudents = 45
minStudents = 1

isValid = False

while isValid == False:
    estStudents = int(input("Please enter the number of students estimated to go:"))
    if estStudents < minStudents or estStudents > maxStudents:
        print("Error - student number invalid")
    else:
        isValid = True


freeTickets = estStudents // 10
print("Free Tickets:", freeTickets)
totalCostOfTickets = (estStudents-freeTickets) * costOfTicket
totalCostTrip = totalCostOfTickets + coachCost
costPerStudent = round(totalCostTrip/estStudents,2)
print("Total cost of Tickets", totalCostOfTickets)
print("Total cost of Trip", totalCostTrip)
print("Total cost per student", costPerStudent)

paidArray = []
notpaidArray = []
counter = 0
loop = True
while counter < 45 or loop == True:
    name = input("Enter the name of the Student going: or -1 to quit")
    if name == "-1": #stop names
        loop = False
        break

    paid = input("Have they paid? Y or N")
    if paid == "Y":
        paidArray.append(name)
    else:
        notpaidArray.append(name)
    counter = counter + 1
    
print("Paid", paidArray)
print("Not Paid", notpaidArray)


totalReceived = len(paidArray) * costPerStudent
print("Total Money received:", totalReceived)
print("Total Cost of Trip", totalCostTrip)

if totalReceived > totalCostTrip:
    print("Profit made", totalReceived-totalCostTrip)
elif totalReceived < totalCostTrip:
    print("Loss Made", totalCostTrip-totalReceived)
else:
    print("Break Even")

Avatar of KingCobra280

cool, I only understood a bit

Avatar of KingCobra280

I do coding a bit but not much :/

Avatar of Xhive24

print ("I only understood print)

Avatar of KingCobra280

I understood a bit more like the loops and if else 

Avatar of Lord_Ultron

which language? definitely not java

seems correct tho

Avatar of Stormbreaker1239
It's python...
I understood the code,nice one @SpeedyCyclone
Avatar of antisunechess

the while statement at the top makes no sense, it just seems like it will look for infinity right

Avatar of antisunechess

and if it doesn't it will just work as a bad if statement

Avatar of antisunechess

wait nvm it makes more sense nowbut it is still kind of bad, you could use a break statement

Avatar of M1m1c15
Good job I prefer c# tho
Avatar of antisunechess
if name == "-1": #stop names
        loop = False
        break

here either the break isn't needed or the loop - false isn't needed
Avatar of antisunechess

also you generally want to not use constant values in your code, try to only declare them in the beginning and only reference them throughout the code, it helps for easy editing

Avatar of SpeedyCyclone

Okay thanks! happy.png