Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Concept explainers

Question
Book Icon
Chapter 11, Problem 5PE
Program Plan Intro

Python functions

Program plan:

  • Define the function “count(myList,x)”,
    • Returns the count of the given “x” value.
  • Define the function “isin(myList,x)”,
    • Returns “True”, if the value “x” is present in the list.
  • Define the function “index(myList,x)”,
    • Returns the index or position of the given “x” value.
  • Define the function “reverse(myList)”,
    • Return a new list consists of the elements which are reversed.
  • Define the function “sort(myList)”,
    • Return a new list consists of the elements which are sorted.
  • Define the function “main()”,
    • Create a list “myList” with the elements.
    • Assign the value of “x”.
    • Print the value return from “count(myList,x)”.
    • Print the value return from “isin(myList,x)”.
    • Print the value return from “index(myList,x)”.
    • Print the value return from “reverse(myList)”.
    • Print the value return from “sort(myList)”.
  • Call the “main()” function.

Blurred answer
Students have asked these similar questions
Write a recursive function named Multiply2 that multiples by 2 and prints each element in a given list. For example: mylist=[1,2,3,4] Multiply2(mylist) prints: 2 4 6 8 Note: the function takes only one parameter, which is the list on which the operation will be performed.
Assume that L is a list of Boolean values, True and False. Write a program in python with a function longestFalse(L) which returns a tuple (start, end) representing the start and end indices of the longest run of False values in L. If there is a tie, then return the first such run. For example, if L is False False True False False False False True True False False 0 1 2 3 4 5 6 7 8 9 10 then the function would return (3, 6), since the longest run of False is from 3 to 6.
Write a recursive function that finds the minimum value in an ArrayList. Your function signature should be public static int findMinimum(ArrayList<Integer>) One way to think of finding a minimum recursively is to think “the minimum number is either the last element in the ArrayList, or the minimum value in the rest of the ArrayList”. For example, if you have the ArrayList [1, 3, 2, 567, 23, 45, 9], the minimum value in this ArrayList is either 9 or the minimum value in [1, 3, 2, 567, 23, 45] Hint:The trick is to remove the last element each time to make the ArrayList a little shorter.     import java.util.*; public class RecursiveMin{public static void main(String[] args){Scanner input = new Scanner(System.in);ArrayList<Integer> numbers = new ArrayList<Integer>();while (true){System.out.println("Please enter numbers. Enter -1 to quit: ");int number = input.nextInt();if (number == -1){break;}else {numbers.add(number);}} int minimum =…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education