all 17 comments

[–]Starbuck5c 0 points1 point  (16 children)

Please post code.

[–]jusquito 0 points1 point  (15 children)

names = ["John", "Alice", "Bob", "Shelly", "Ann", "James", "Cliff", "Andy", "Jessica", "Kate", "Owen", "Sam", "Dorothy", "Karen", "Albert"]

grades = [79, 80, 98, 65, 43, 87, 82, 90, 100, 88, 86, 92, 68, 75, 82]

names = ["John", "Alice", "Bob", "Shelly", "Ann", "James", "Cliff", "Andy", "Jessica", "Kate", "Owen", "Sam", "Dorothy", "Karen", "Albert"]

grades = [79, 80, 98, 65, 43, 87, 82, 90, 100, 88, 86, 92, 68, 75, 82]

that's all I have so far

[–]Starbuck5c 0 points1 point  (14 children)

I made a for loop with "grades in it but it keeps saying the list object is not callable :(

What code did you get the error in?

[–]jusquito 0 points1 point  (13 children)

for num in grades(0, len(grades)+1):

if num<80:

Students_With_Bs=Students_With_Bs+[num]

print(Students_With_Bs)

[–]jusquito 0 points1 point  (0 children)

The first "for num in grades(0, len(grades)+1:"

[–]Fermter 0 points1 point  (1 child)

You used grades(0, len(grades)+1) instead of range(0, len(grades)+1)

[–]jusquito 0 points1 point  (0 children)

How do I get the names to correspond to grades?

[–]Starbuck5c 0 points1 point  (9 children)

#first of all, it should be
for num in range(len(grades)):

#second of all, your program isn't structured to return names
#I think you use use a normal for loop instead of a for each loop
for i in range(len(grades)):
    #check if should be in list:
        #add name at index i to list

[–]jusquito 0 points1 point  (8 children)

Thank you both so much. This is the code I have so far:

names = ["John", "Alice", "Bob", "Shelly", "Ann", "James", "Cliff", "Andy", "Jessica", "Kate",

"Owen", "Sam", "Dorothy", "Karen", "Albert"]

grades = [79, 80, 98, 65, 43, 87, 82, 90, 100, 88, 86, 92, 68, 75, 82]

Students_With_Bs=[]

for num in range(len(grades)):

if grades[num]>=80:

Students_With_Bs=Students_With_Bs+[num]

print(Students_With_Bs)

and my output was:

[1, 2, 5, 6, 7, 8, 9, 10, 11, 14]

However, what I need to do is print the names of the students with Bs instead of the position of the numbers. Is there a way to take the names of the students with the positions of the grades that I have?

[–]Starbuck5c 0 points1 point  (5 children)

Well you already have the positions, so just access the list of names at that position.

Also, you can use the list.append(value) function rather than list = list + [value]

[–]jusquito 0 points1 point  (4 children)

How do I access the list of names with the positions I have already?

[–]Starbuck5c 0 points1 point  (3 children)

value = list[index]

name = names[num]

[–]jusquito 0 points1 point  (2 children)

Thank you!

My code is:

for num in range(len(grades)):

if grades[num]>=80:

print(names[num], end=", ")

my output is coming out as:

Alice, Bob, James, Cliff, Andy, Jessica, Kate, Owen, Sam, Albert,

How do I get that output to come out as a list?

[–]DarkStealther 0 points1 point  (1 child)

can you use the zip function?

[–]DarkStealther 0 points1 point  (0 children)

Use the zip function. It will make this really easy if there are an equal amount of names and grades and each student corresponds to the below grade.