Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The program has 3 lists each with 10 values. I need to take inputs from all 3 lists one by one (or by index?) and apply conditions to those values.

for each output, the inputs must be one from each list. Finally there should be 10 outputs.

Thank you!

What I have tried:

Python
passes = [120,100,80,60,40,20,20,20,0]
not_attempted = [0,20,0,20,40,40,40,20,0,0]
fail = [0,0,20,20,20,40,60,80,100,120]

if pass==120:
  print('A')
elif pass==100:
  print('B')
elif fail>=60:
  print('F')
else:
  print('C')
Posted
Updated 21-Aug-21 8:01am
Comments
Member 15009895 8-Dec-20 11:06am    
I passed through two range arguments (0,10) and then the conditional statements. That did the trick.

You need to an index into each of the lists: Python - Lists - Tutorialspoint[^]
And then set up a loop: Python for Loop Statements - Tutorialspoint[^] to provide you with the index value to access the collections with.
 
Share this answer
 
Comments
Member 15009895 8-Dec-20 11:06am    
Thank you
OriginalGriff 8-Dec-20 11:17am    
You're welcome!
Python
for i in range(len(passes)):
    pass = passes[i] # this selects the next item in a list
# add your code here which will be processed for the number of elements in each list.
 
Share this answer
 
Comments
Member 15009895 8-Dec-20 11:05am    
Thank you guys for the help. I figured it out. Instead of using len, I only passed through two range arguments (0,10) and then the conditional statements. That did the trick.
Richard MacCutchan 8-Dec-20 11:11am    
There is a good reason for using len(). It allows you to process a list of any length, which may be important if you receive the list from some external source. Also you do not need the initial zero as that is the default, so range(10) actually means: starting at zero, do ten repeats, incrementing the index counter by one each time. This is all explained at 4. More Control Flow Tools — Python 3.7.9 documentation[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900