Question

i=2 j=0 while(i!=len(data)): if(data[i][0][0]>="A" and data[i][0][0]<="E" and data[i][1]=="Mammal"): print(data[i][0]) i=i+1 Could you explain what the first...

i=2
j=0
while(i!=len(data)):
if(data[i][0][0]>="A" and data[i][0][0]<="E" and data[i][1]=="Mammal"):
print(data[i][0])
i=i+1

Could you explain what the first 2 lines of code mean in this program?

As well as the while loop regarding the "data[i][0][0]" and "data[i][0]" in the fourth line?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// declare a variable i and initialize it to 2. To initialize means to provide an initialize value to the variable

i=2

// declare a variable j and initialize it to 0.
j=0

//while loop - it is used for iteration

//data is an array . The while loop will check if the value of i is not equal to the length of the data

//If true, program control will go to the while block

//If false, it will go to the statement outside the block
while(i!=len(data)):

//This if condition will check if ith row's 1st column element is between A and E ie. if it is A, B, C, D, E . Also, it will check if second column of ith row is equal to Mammal

//If the conditions are true. the program control will go to the next program block other wise not
if(data[i][0][0]>="A" and data[i][0][0]<="E" and data[i][1]=="Mammal"):

//Print the element in the 1st column of the ith row
print(data[i][0])

//increase the value of i by 1
i=i+1

(The program will basically iterate through the array , check if the first column is either A,E,C,D,E and the second column is Mammal. If found it will print that element and increment 1 by 1.)

Add a comment
Know the answer?
Add Answer to:
i=2 j=0 while(i!=len(data)): if(data[i][0][0]>="A" and data[i][0][0]<="E" and data[i][1]=="Mammal"): print(data[i][0]) i=i+1 Could you explain what the first...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT