Jump to content

Algorithm sub program


Potter1245

Recommended Posts

The data in the table below has been collected by a teacher at the end of two unit assessments. Produce a subroutine for an algorithm that could be used to count the number of students who achieved a grade 8 in both assessments, the data is stored in parallel arrays and array indexing begins at 0

Ryan. 5. 5

Liam. 8. 8

Sophie. 5. 7

Micheal 3. 4

Robert 8. 8

Rebecca. 5. 3

Link to comment
Share on other sites

You haven't said if the information in each line is all one string or in columns or what ?

In any case you need to start by telling us what you have done or think might be done.

Hint  : I would start with the last character in each line

Link to comment
Share on other sites

May we assume 8 is the highest grade?

16 minutes ago, Potter1245 said:

data is stored in parallel arrays and array indexing begins at 0

I'll assume that you have two arrays containing 6 integers each:

5, 8, 5, 3, 8, 5 

and

5, 8, 7, 4, 8, 3 

As a stating point, do you know how to loop through arrays and use the index to access values? 

 

Link to comment
Share on other sites

31 minutes ago, Potter1245 said:

8 is the highest grade

Thanks! Now, let's say we have both the grades for a student, any idea how we could find out if both grades are 8? You could answer something in plain English like "if grade is this then do this..."

 

31 minutes ago, Potter1245 said:

I don’t know how to loop guys, pls help

A loop in this case means some way the algoritm uses to go through the array(s), step by step. A loop may be useful to check grades and do counting. 

Below is an example of a loop. It means: "go through the grades, one by one, and do something." In this case it prints the grades. 

grades = [5, 8, 5, 3, 8, 5 ]
for x in grades:
  print(x) 

The above can be copy-pasted into an online tool such as w3schools* if you want to test. 

 

*) in chis specific case you may start here: https://www.w3schools.com/python/trypython.asp?filename=demo_for

 

 

Edited by Ghideon
edit in progress
Link to comment
Share on other sites

  • 3 weeks later...
On 2/27/2021 at 5:28 PM, Ghideon said:

The above can be copy-pasted into an online tool such as w3schools* if you want to test. 

..but OP didn't say the answer should be in Python...

Edited by Sensei
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.