#πŸ”’ Homework need help

25 messages Β· Page 1 of 1 (latest)

dapper adder
#

elements=int(input("How many students: "));

the task is to make it so you can input students names and their mark and then for the code to print the students who got above the average mark and who got below. I have gotten the part where it prints what marks scored above the average however I am struggling to figure out how I can get it to print the name of student who got that mark.

Any help would be appreciated and sorry I do not know how to write a message on discord with the box around it.

students = [];
marks = [];

for x in range(elements):

name = input("Name of the student:  ");

grade = int(input("Marks for that student: "));

students.append(name);

marks.append(grade);

average_mark = (sum(marks)/len(marks))
print(f"\nAverage Mark: {average_mark}\n")

print("students above average mark: ")
for x in marks:
if x > average_mark:
print(x);

static mulchBOT
#

@dapper adder

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

brave lodge
#

```py
code in here
```

#

some possible solutions:

  • loop through the index instead of the values
  • zip
  • bundle the student's name and grade together when you were inputting
dapper adder
#

would it be possible to have both the grade and name in the same list or would that not work because one is an int and other is a string?

#

sorry I am just confused

brave lodge
#

but obv if you have this list

['Alice', 95, 'Bob', 80, 'Cathy', 93]
```then it's a bit more complicated to loop
pliant cipher
#

<strike>... there's also zip...</strike> sorry, Purplys already mentioned it.

dapper adder
#

what is zip?

brave lodge
# dapper adder what is zip?

!e quicker if I showed you

a = ['Alice', 'Bob', 'Cathy']
b = [90, 85, 93]

for x, y in zip(a, b):
    print('Name:', x, 'Score:', y)
static mulchBOT
spiral lake
#

It also bears mentioning that you needn't include semicolons as a statement termination character.

dapper adder
#

sorry I am trying to learn C# outside of school but python is something doing in class

#

Its turned into a bad habit

spiral lake
#

To each language its own conventions.

pliant cipher
#

If the example above is unclear, try: print(list(zip(a,b))) or whatever your 2 lists are named (students etc)

dapper adder
#

ok let me give it a try

brave lodge
#

you can also do it without all the fancy stuff
i.e. iterate thru the index

dapper adder
#

Thankyou

#

I guess I should go learn what zip actually is

static mulchBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

πŸ”’ Homework need help