Specimen Paper IGCSE Practice


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<In what way does your code behave incorrectly? Include ALL error messages.>

<What do you expect to happen instead?>
This code is part of my specimen paper for my igcse mocks in December. I have issues with the top line of code, because when it asks for the name of the student it prints 4 different students names and ask for their grades. I want the code just to ask for the students name and their grades not for 4 different ones. Can someone help me


name = input("Enter Student name:")
students = 4
Test_1 = 20
Test_2 = 25
Test_3 = 35
total_score = Test_1 + Test_2 + Test_3
average_score = Test_1 + Test_2 + Test_3 / 3 * 100
highest_score = Test_1 + Test_2 + Test_3 / 4 
list_1 = ['Bob', 'Bobert' , 'Gorgie' , 'Dereck']
def display():
    s1 = []
    for i in range(students):
        s1.append(i)
    return s1
display()
for names in list_1:
 Test_1 = int(input("What did "+names+" get on their test?"))
if Test_1 > 0 < 20:
  print("You have failed!")
else:
  print("You have passed!")
for names in list_1:
  Test_2 = int(input("What did "+names+" get on their test?"))
if Test_2 > 0 < 25:
  print("You could have done better!")
else:
  print("You have done well!")
for names in list_1:
  Test_3 = int(input("What did "+names+" get on their test?"))
if Test_3 > 0 < 35:
  print("You could have done better!")
else:
  print("You have done well!")
print("Input the total score of the students "+names+" out of all three tests!")
if total_score < 0 > 80:
  print("Your grade is U")
if total_score < 10 > 80:
  print("Your grade is G")
if total_score < 20 > 80:
  print("Your grade is F")
if total_score < 30 > 80:
  print("Your grade is E")
if total_score < 40 > 80:
  print("Your grade is D")
if total_score < 50 > 80:
  print("Your grade is C")
if total_score < 60 > 80:
  print("Your grade is B")
if total_score < 70 > 80:
  print("Your grade is A")
if total_score < 80 > 80:
  print("Your grade is A*")
  
if highest_score < 0 > 80:
  print()

print("The average score was {}".format(average_score))

#2

so, a single student, which you get using input(), that is good

how many grades should this student have?

If you just want a single student, why do you have:

list_1 = ['Bob', 'Bobert' , 'Gorgie' , 'Dereck']

#3

The code is made so that there are 30 students in the class and all the grades must be entered for one select person at a time before printing out the highest score in the class and the name of the student. But I have decided to make tthe code for 4 students before changing the code for 30. I can post a picture of the tasks set.


#4

so 30 students, and each student has a single grade?

i would use a dictionary, so you can associate students and there grades, for example:

{'mark': 70, 'julia': 75}

then it sounds like you need a loop with range, so we can prompt for the 30 students (or first 4, for testing is easier):

students_dictionary = {}
for i in range(4):
    name = input("Enter Student name:")
    grade = int(input("What did {} get on their test?".format(name)))
    # saving into dictionary
    students_dictionary[name] = grade

#5

Sure that helps. But the students have taken three tests each with a maximum mark. I want to be able to type in the grade for each student before the code prints out the highest mark out of the class along with student name. But it must also print out the average mark the class got as well.


#6

then we can do the following:

{'mark': [60,70,80], 'julia': [65, 75, 85]}

this way, we have 3 grades for each student, that is what you want? I will leave you for a minute to think about the code needed to achieve this. Dictionaries consist of key and value pairs, so in the above example mark is a key, [60,70,80] its associated value. values of dictionaries can be list (perfectly valid)

that is possible, you need to slightly modify the code i gave you to allow for 3 grade inputs instead of the one i showed in the example:

# this needs modifying
grade = int(input("What did {} get on their test?".format(name)))

currently, this allows for one grade to be entered (per student), so you will need to make 3 inputs or 1 input that accepts 3 values


#7

Ok. Thanks I shall try the code above


#8

what code? this:

{'mark': [60,70,80], 'julia': [65, 75, 85]}

shows the final result of the dictionary we are building, you still need to write the code to get this result

and this:

students_dictionary = {}
for i in range(4):
    name = input("Enter Student name:")
    grade = int(input("What did {} get on their test?".format(name)))
    # saving into dictionary
    students_dictionary[name] = grade

still needs modifying to suit the needs of your program, so not sure what code you are going to try

you need to write code, its your assignment, i am just pushing you a little bit in the right direction


#9

I know that this is my assignment I’m just asking for a bit of help in order for me to finish this assignment. I have spent a lot of time, on the code but I seem to get stuck on the grade part.


#10

Please post an updated version of your code need more help

lets do one of the 30 students, lets say a student has 3 grades (for grade_1, grade_2 and grade_3)

do we need to apply checks (within a certain range for example) to grade_1, grade_2 and grade_3?


#11
name = input("Enter Student name:")
grade = int(input("What did {} get on their test?".format(name)))
grade_Test_1 = int(input("What did {} get on their test?".format(name)))
grade_Test_2 = int(input("What did {} get on their test?".format(name)))
grade_Test_3 = int(input("What did {} get on their test?".format(name)))
students_class = 4
names_students = 4
grade_Test_1 = 20
grade_Test_2 = 25
grade_Test_3 = 35
grade_Tests = 80
total_score = grade_Test_1 + grade_Test_2 + grade_Test_3
average_score = grade_Test_1 + grade_Test_2 + grade_Test_3 / 3 
highest_score = grade_Test_1 + grade_Test_2 + grade_Test_3 / 4 
list_1 = ['Bob', 'Bobert' , 'Gorgie' , 'Dereck']
students_dictionary = {}
for i in range(3):
    students_dictionary[name] = grade_Tests
def display():
    s1 = []
    return s1
display()
for names in list_1:
 grade_Test_1 = int(input("What did "+names+" get on their test?"))
if grade_Test_1 > 0 < 20:
  print("You have failed!")
else:
  print("You have passed!")
for names in list_1:
  grade_Test_2 = int(input("What did "+names+" get on their test?"))
if grade_Test_2 > 0 < 25:
  print("You could have done better!")
else:
  print("You have done well!")
for names in list_1:
  grade_Test_3 = int(input("What did "+names+" get on their test?"))
if grade_Test_3 > 0 < 35:
  print("You could have done better!")
else:
  print("You have done well!")

total_score = int(input("Input the total score of the students "+names+" out of all three tests!"))  
print(total_score)
if total_score < 0 > 80:
  print("Your grade is U")
if total_score < 10 > 80:
  print("Your grade is G")
if total_score < 20 > 80:
  print("Your grade is F")
if total_score < 30 > 80:
  print("Your grade is E")
if total_score < 40 > 80:
  print("Your grade is D")
if total_score < 50 > 80:
  print("Your grade is C")
if total_score < 60 > 80:
  print("Your grade is B")
if total_score < 70 > 80:
  print("Your grade is A")
if total_score < 80 > 80:
  print("Your grade is A*")
  
if highest_score < 0 > 80:
  print("This is a disapointment")
if highest_score < 10 > 80:
  print("Your score wasn't high enough to be considered")
if highest_score < 20 > 80:
  print("Your score was lower than expected, but still not high enough to be considered")
if highest_score < 30 > 80:
  print("Your score was low, but not high enough to be considered")
if highest_score < 40 > 80:
  print("Your score was acceptable, but you need to work more")
if highest_score < 50 > 80:
  print("Your score was okay, but it could be improved")
if highest_score < 60 > 80:
  print("Your score is good, but it could be better") 
if highest_score < 70 > 80:
  print("Your score was one of the best in the class!")  
if highest_score < 80 > 80:
  print("Congrats your score was one of the highest in the class")  
  
  
  
  

print("The average score was {}".format(average_score))
print("The highest score in the class was achieved by {}, and their score was {}".format(names_students,highest_score))

When i ran the code, it prints out Bob’s name 5 times, if i type in Bob. Why is this? How can i fix it?


#12

this:

name = input("Enter Student name:")
grade = int(input("What did {} get on their test?".format(name)))
grade_Test_1 = int(input("What did {} get on their test?".format(name)))
grade_Test_2 = int(input("What did {} get on their test?".format(name)))
grade_Test_3 = int(input("What did {} get on their test?".format(name)))

should be in a loop, given we need to get the name of 30 students and there 3 grades from the end user (end user = user using our program)

this line can be removed:

grade = int(input("What did {} get on their test?".format(name)))

its not doing anything.

here:

grade_Test_1 = 20
grade_Test_2 = 25
grade_Test_3 = 35

you overwrote the grades the user just inputted, why? Doesn’t make sense, remove it as well

this doesn’t make sense either:

list_1 = ['Bob', 'Bobert' , 'Gorgie' , 'Dereck']

we should get the names from the end user, so not sure why you hard code a list of names into your program

Show me the assignment. Don’t you have a teacher you can ask? It feels like i am not capable of helping you. It doesn’t feel like (from my point of view) that we are getting closer to solve your problem


#13

Sure. Would you like the assignment typed or as a photo


#14

does it matter for you? I think for this screenshot is fine. (or photo, if ensured its readable)

typed is also fine, if not too much work


#15

Here is the task with all the parts. Hope this help to solve the problem I’m having.

TASK 1
Input and store the names and marks for 30 students who have sat three computer science tests.
Test 1 is out of 20 marks, Test 2 is out of 25 marks, Test 3 is out of 35 marks. You must store the
names in a one-dimensional array and the marks and total score for each student in one-dimensional
arrays. All the marks must be validated on entry and any invalid marks rejected. You may assume
that the students’ names are unique.
TASK 2
Calculate and store the total score for each student and calculate the average score for the whole
class. Output each student’s name followed by their total score, then output the average score for the
class.
TASK 3
Select the student with the highest score and output their name and score.
Your program must include appropriate prompts for the entry of data. Error messages and other
output need to be set out clearly and understandably. All variables, constants and other identifiers
must have meaningful names. Each task must be fully tested.


#16

well, in that case, given we need to use lists, we need to make a slight modification to the code:

names = []
grades = []
for i in range(4):
    name = input("Enter Student name:")
    grade = int(input("What did {} get on their test?".format(name)))
    # saving name and grade
    names.append(name)
    grades.append(grade)