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
Most languages do not have the flexible built-in list (array) operationsthat Python has. Write an algorithm for each of the following Pythonoperations and test your algorithm by writing it up in a suitable function. For example, as a function, reverse (myList ) should do the same asmy List . reverse ( ) . Obviously, you are not allowed to use the corresponding Python method to implement your function.a) count (my List , x) (like my List . count (x) )b) isin(myList , x) (like x in myList))c) index (my List , x) (like my List . index (x) )d) reverse (myList) (like myList . reverse ())e) sort (myList) (like my List . sort ())
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] ================================================ 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 = findMinimum(numbers);System.out.println("Minimum: " + minimum);}public static int…
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