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?
// 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.)
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...
LOVOU AWN 1. def remove_all_from_string(word, letter): i=0 3. while i<len(word)-1: if word[i] = letter: num = word.find(letter) word - word[:num] + word[num+1:] i=0 i=i+1 return word 10 print remove_all_from_string("hello", "1") 5 points Status: Not Submitted Write a function called remove_all_from_string that takes two strings, and returns a copy of the first string with all instances of the second string removed. This time, the second string may be any length, including 0. Test your function on the strings "bananas" and "na"....
Predict the outcome of each line: F1 F0 while i<10: i+=1 j+=2*2 print(i) #Line 1 print() # Line 2
For JAVA Please post code in bold. Thank you. Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Challenge 4.6.1: Nested loops ndent...
How many Iterations will this while loop perform? int ico), j(10); cout << "i = " << i << endl; cout << "j = " << j << endl; while (i > j) { cout << "j-" « j << endl; j += 2; cout << "i = " << i << endl; } cout << "i = << i << endl; cout << "j = " << j << endl; 5 6 C 8 10 Infinite times Does the...
You will create a new project. Type in the following program and run it to produce the output for the program. Good practice in writing a program in any language, including Python, is to add comments for each line and state clearly what is the program input and output. Your program must include comments, so a reader will know exactly what you are trying to do in each line of code and allow for easy maintenance. Beginning a line with...
What is the result of the following: print(input("Enter a number")* 2) if you entered 9. oooo 13 Error What is the result of t = (1, 3.5): t.append(7) O (1,3,5,7) O (1,3,5) O (7) Error To check if there is a WIN in a tic-tac-toe game, the program has to check * O 6 lines of 3 boxes O 8 lines of 3 boxes O 9 boxes O The Center What is the result of print( int("3" + "5") +...
Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Sample program: #include <stdio.h> int main(void) { int userNum = 0; int i =...
def selectionSortK(alist, k): for i in range(0,len(alist) - 1): min = i for j in range(i + 1, len(alist)): if alist[j] < alist[min]: min = j temp = alist[i] alist[i] = alist[min] alist[min] = temp P3: Sanity Test: Is selectionSortK callable? ... ok test_doNothing (__main__.TestProblem3) P3: Does sorting the first k elements with k=0 do nothing? ... ok test_onePass (__main__.TestProblem3) P3: Sorting a portion of a decreasing list ... FAIL test_severalPasses (__main__.TestProblem3) P3: Sorting a decreasing list in several stages...
Consider the following lines of Matlab code 1 arr-14,7.2,5,1,6: 2 for j 2:length(arr) 3 key arr) 4 i j-1; 5 while i - 1 && arr)> key 6 arr(+1) arr(); 8 end %end of while loop 9 arr(+1) key 10 end %end of for loop After line 8 gets executed the first time, the state of the array arr is. arr [4, 7, 7, 5, 1, 6] What is the state of the array arr after line 8 is executed...
Python: Could you please say step by step how the output is coming? I understand about importing and getting random number but how the inner loop is working? Code: import random li1 = [[random.randrange(5) for i in range(3)] for j in range(4)] print("First output : {}".format(li1)) ncol = 4 nrow = 5 li2 = [ [random.randrange(2) for i in range(ncol) ] for j in range(nrow) ] print("Second output : {}".format(li2)) Output: First output : [[3, 2, 4], [2, 3, 2],...