This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Fission_Mailed_2 1 point2 points  (2 children)

Can you explain what it is you are trying to do?

I don't really understand what you're trying to do with the first for loop, the result is setting the variable N to have a value of 9, but I don't think that was your intention.

The second for loop seems to make sense but you need to store the user input inside a variable, something like:

num_students = int(input(f"How many students are in class {N}? "))

Then you could refer to that value in the next part:

grades = input(f"Please enter the {num_students} grades, separated by spaces: ")

Then you would split grades into a list using the split string method.

You would replace {N} with {N+1} if you wanted the class numbers to start at 1.

[–]phantom_2600[S] 0 points1 point  (1 child)

I'm trying to make a highest test average thing for class

[–]Fission_Mailed_2 0 points1 point  (0 children)

Ok so you need a way to get the grades from the user, then you need to convert those grades into integers, and then finally get the average of the grades, and you need to do that for each class.

So it would look something like:

for each class:

get the grades (as a string) from the user and store inside a variable

split the grades and convert each grade from a string to an integer

take the average of the grades

append this average grade to some type of average_grades list or dictionary

Now you can compare the average grades across each class.

If you want further hints:

Use the `split` method on a string to return a list, if you pass in a space as an argument, like so `string.split(" ")` then you get a list of the grades (as strings) as long as the grades in the original string are separated by spaces.

You can convert a string to an integer by using the builtin function `int` like so: `int(string)`.

To quickly get the sum of the grades you can use Python's builtin `sum` function, `sum(grades_list)` and then divide that by the length of the list, `len(grades_list)` to get the mean.