Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 8

Write for loops that iterate over the clements of a list without the use of the range function for the following tasks. a. Printing all elements of a list in a single row, separated by spaces. b. Computing the product of all elements in a list. c. Counting how many elements in a list are negative.

Problem 8

Compute the altemating sum of all elements in a list. For example, if your program reads the input then it computes 1491697491114+916+97+49+11=2

Problem 9

Write a function that reverses the sequence of elements in a list. For example, if you call the function with the list 14916974911 then the list is changed to 11947916941

Problem 9

What is an index of a list? What are the legal index values? What is a bounds error?

Problem 11

Write a function def equals (a,b) that checks whether two lists have the same elements in the same order.

Problem 11

Write a loop that reads ten numbers and a second loop that displays them in the opposite order from which they were entered.

Problem 12

For the operations on lists below, provide the header and function comment for a function. Do not implement the functions. a. Sort the elements in decreasing order. b. Print all clements, separated by a given string. c. Count how many elements are less than a given value. d. Remove all clements that are less than a given value. e. Place all elements that are less than a given value in another list.

Problem 12

Write a function def saneset (a,b) that checks whether two lists have the same elements in some order, ignoring duplicates. For example, the two lists and 1111791641 would be considered identical. You will probably need one or more helper functions.

Problem 13

Write a function def saneflenents (a,b) that checks whether two lists have the same clements in some order, with the same multiplicities. For example, 14916974911 and 11149169749 would be considered identical, but 14916974911 and 111179164149

Problem 15

Write a program that generates a sequence of 20 random die tosses in a list and that prints the die values, marking only the longest run, like this: 1255312.43(2222)3655631 If there is more than one run of maximum length, mark the first one.

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks