The for() loop as given below:
for i in range (len(text))
will execute for i = 0 to i = len(text) - 1
The equivalent while() loop is given below:
i = 0
while i < len(text):
i += 1
The screenshot of the equivalent while() loop is given below:

identify the code that sorts the numbers in descending order. def selection_sort(numbers): for i in range(len(numbers) - 1): index = i XXX temp = numbers[i] numbers[i] = numbers[index] numbers[index] temp for j in range(i + 1, len(numbers): if numbers[j] > numbers[index]: index اله for j in range(i - 1, len(numbers): if numbers[j] > numbers[index]: index j for j in range(i + 1, len(numbers)): if numbers[j] < numbers[index]: index j for j in range(i 1, len(numbers): if numbers [j] < numbers[index]:...
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...
What is the loop INVARIANT for this program? The loop variant
has to pass the premises:
loop {P) [U] while (b) (Sj1 S fQ) (0 S len)) i=0; r false; while (i < len) { if (a ] r) { r = true; i = len; else r true)
loop {P) [U] while (b) (Sj1 S fQ)
(0 S len)) i=0; r false; while (i
Describe a situation where a for loop would be preferred over a while loop. Describe a situation where a while loop would be preferred over a for loop. How is a for loop similar to a while loop? In what way or ways are for and while loops different?
How do I make this program run the same using a do while loop instead of the for loop? I'm supposed to replace the for loop with a do-while. Also, how would i replace it with a while loop? #include void main(void) { int n, sum, product, i; printf("n?\n"); scanf("%i", &n); printf("You entered %i\n", n); sum = 0; product = 1; for (i=1; i<=n;i++) { if((i%3!=0) && (i%5!=0)){ sum = sum + i; product = product * i;} ...
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"....
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?
Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...
C++ Visual Studio 1. How many iterations are in the following "while" loop? int i = 0; while(i < 20) { ++i; } 2. How many iterations are in the following "for" loop? for(int i = 5; i < 17; i = i + 2) { // Work } How many times will '+' be printed? int i = 0; while(true) { if(i == 5) { break; } cout << "+"; ++i; } 3. How many times will '+' be...
Calculate the space required by the below programs: a- n = len(S) # S has 15 numbers j = 0 while j < n: if S[j] == val: return j # a match was found at index j j += 1 b- n = len(S) total = 0 for j in range(n): # loop from 0 to n-1 for k in range(1+j): # loop from 0 to j total += S[k] return total c- data=[15,14,8,12,4] big = data[0] for val...