python - How to say something when a particular value you're looking for is not in a list -



python - How to say something when a particular value you're looking for is not in a list -

i'm working on assignment school , got done i'm missing little crucial piece.

so total assignment user come in in values grades pupil gets list, user must able see average of particular subject or printed out version of grades students got subject.

my problem how set tell user there isn't values particular subject when selects see avg/all values subject. i'll show here got list has values in, there's no need go through whole process of putting them in

cijfers = [ [ 12345, 'wiskunde', 8.9], [ 12345,'elnet', 4.0], [12345, 'python', 8.9], [98761, 'wiskunde', 6.5], [98761, 'elnet', 7], [98761, 'python', 4.5], [20945, 'wiskunde', 5],[20945, 'elnet', 6.9], [20945, 'python', 4.5], [65489, 'wiskunde', 3.4], [65489, 'elnet', 6.7], [65489, 'python', 10]]

first 1 stands pupil number, sec 1 subject , 3rd 1 grade that particular pupil got.

so if set give me grades subject "wiskunde"

cijfers = [ [ 12345, 'wiskunde', 8.9], [ 12345,'elnet', 4.0], [12345, 'python', 8.9], [98761, 'wiskunde', 6.5], [98761, 'elnet', 7], [98761, 'python', 4.5], [20945, 'wiskunde', 5],[20945, 'elnet', 6.9], [20945, 'python', 4.5], [65489, 'wiskunde', 3.4], [65489, 'elnet', 6.7], [65489, 'python', 10]] = 0 print (' tentamencijfers voor: ','wiskunde', '\n', '========================================') print (' studenten# | cijfer') while (a<len(cijfers)): if (cijfers [a][1] == 'wiskunde'): print (' ',cijfers[a][0], ' ',cijfers[a][2]) = + 1

it gives me follow output:

tentamencijfers voor: wiskunde #translates exam grades for: math ======================================== studenten# | cijfer 12345 8.9 98761 6.5 20945 5 65489 3.4

which supposed do, let's if there wasn't values "wiskunde" list this:

cijfers = [ [ 12345,'elnet', 4.0], [12345, 'python', 8.9], [98761, 'elnet', 7], [98761, 'python', 4.5], [20945, 'elnet', 6.9], [20945, 'python', 4.5], [65489, 'elnet', 6.7], [65489, 'python', 10]]

it give me output:

tentamencijfers voor: wiskunde #translates exam grades for: math ======================================== studenten# | cijfer

i know shows little bit because wrote "print" function before "while" that's not question.

so question how can create give me simple "there's no values set in particular subject"?

to strictly reply question, add together counter , alter loop in next way:

count = 0 in cijfers: if (cijfers i[1] == 'wiskunde'): count += 1 # same count = count + 1 print (' ',i[0], ' ',i[2]) #out of loop: if count == 0: print "there's no values set in particular subject"

as info structure, think dictionary improve suit needs, using key pupil number; check them out!

python python-3.x nested-lists

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -