Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133743692
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 7.5, Problem 17CP
Program Plan Intro
Method “append()”:
- • In Python, the method “append()”can add an element to the end of the list.
- • The data that need to be appended to the list can be passed as an argument to the method “append()”.
Syntax:
In Python, the method “append()” can be expressed as follows:
append(element)
Explanation:
- • “element” that is passed as an argument to the method “append()” will be append to the end of the list.
- • When the list is empty, the “append()” method adds the “element” to index 0.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Assume the following statement appears in a program:mylist = []Which of the following statements would you use to add the string 'Labrador' to the list at index 0?a. mylist[0] = 'Labrador'b. mylist.insert(0, 'Labrador')c. mylist.append('Labrador')d. mylist.insert('Labrador', 0)
Assume the following statement appears in a program:days = 'Monday Tuesday Wednesday'Write a statement that splits the string, creating the following list:['Monday', 'Tuesday', 'Wednesday']
a-)Write a game of rock paper scissors, one of the choices will be from the user and theother from the computer (use random) Print results for each game.Play the games in a row until you exit the game. Explain each step as comment.Game rules:Rock crushes scissors, you win.Paper covers rock, you win.Scissors cut paper, you win.(İn Python)
b-)Write a program that sorts a list in ascending order. Don’t use sort method.Ask user number of list elements (at least 10 elements)Enter all elements from keyboard and printed.Sort your list.(İn python)
c-)Write a code for craps game. Craps is a dice game in which the players make wagerson the outcome of the roll, or a series of rolls, of a pair of dice.The rules of the dice game craps are as follows:You roll two dice. Each die has six faces, which contain one, two, three, four, five and six spots,respectively. After the dice have come to rest, the sum of the spots on the two upward faces iscalculated. If the sum is 7 or 11 on the first throw, you…
Chapter 7 Solutions
Starting Out with Python (3rd Edition)
Ch. 7.2 - What will the following code display? numbers =...Ch. 7.2 - Prob. 2CPCh. 7.2 - Prob. 3CPCh. 7.2 - Prob. 4CPCh. 7.2 - Prob. 5CPCh. 7.2 - Prob. 6CPCh. 7.2 - Prob. 7CPCh. 7.2 - Prob. 8CPCh. 7.3 - Prob. 9CPCh. 7.3 - Prob. 10CP
Ch. 7.3 - Prob. 11CPCh. 7.3 - Prob. 12CPCh. 7.3 - Prob. 13CPCh. 7.4 - What will the following code display? names =...Ch. 7.5 - Prob. 15CPCh. 7.5 - Prob. 16CPCh. 7.5 - Prob. 17CPCh. 7.5 - Prob. 18CPCh. 7.8 - Prob. 19CPCh. 7.8 - Prob. 20CPCh. 7.8 - Write a set of nested loops that display the...Ch. 7.9 - Prob. 22CPCh. 7.9 - Prob. 23CPCh. 7.9 - Prob. 24CPCh. 7.9 - Prob. 25CPCh. 7 - This term refers to an individual item in a list....Ch. 7 - This is a number that identifies an item in a...Ch. 7 - Prob. 3MCCh. 7 - This is the last index in a list. a. 1 b. 99 c. 0...Ch. 7 - This will happen if you try to use an index that...Ch. 7 - This function returns the length of a list. a....Ch. 7 - When the operator's left operand is a list and...Ch. 7 - This list method adds an item to the end of an...Ch. 7 - This removes an item at a specific index in a...Ch. 7 - Prob. 10MCCh. 7 - If you call the index method to locate an item in...Ch. 7 - Prob. 12MCCh. 7 - This file object method returns a list containing...Ch. 7 - Which of the following statement creates a tuple?...Ch. 7 - Prob. 1TFCh. 7 - Prob. 2TFCh. 7 - Prob. 3TFCh. 7 - Prob. 4TFCh. 7 - A file object's writelines method automatically...Ch. 7 - You can use the + operator to concatenate two...Ch. 7 - Prob. 7TFCh. 7 - You can remove an element from a tuple by calling...Ch. 7 - Prob. 1SACh. 7 - Prob. 2SACh. 7 - What will the following code display? values = [2,...Ch. 7 - Prob. 4SACh. 7 - Prob. 5SACh. 7 - Prob. 6SACh. 7 - Prob. 1AWCh. 7 - Prob. 2AWCh. 7 - Prob. 3AWCh. 7 - Prob. 4AWCh. 7 - Write a function that accepts a list as an...Ch. 7 - Prob. 6AWCh. 7 - Prob. 7AWCh. 7 - Prob. 8AWCh. 7 - Total Sales Design a program that asks the user to...Ch. 7 - Prob. 2PECh. 7 - Rainfall Statistics Design a program that lets the...Ch. 7 - Prob. 4PECh. 7 - Prob. 5PECh. 7 - Larger Than n In a program, write a function that...Ch. 7 - Drivers License Exam The local driver s license...Ch. 7 - Name Search If you have downloaded the source code...Ch. 7 - Prob. 9PECh. 7 - World Series Champions If you have downloaded the...Ch. 7 - Prob. 11PE
Knowledge Booster
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
- Assume the following statement appears in a program: names = I"'Ms. Sri"' Write statements to demonstrate how to add your name to the end of the list in three ways: using the insert() method, using the append() method, and using list concatenation. IN PYTHONarrow_forwardPython Help Write a program that reads numbers and adds them to a list if the are not already contained in the list. When the list contains ten numbers, the program displays the contents and quits. Show the analysis, specifications and flowcharts of the two problems Use documentation by commenting your code Write your code in the script modearrow_forwardAssume that the following statement appears in a program: my_string = "cookies>milk>fudge>cake›ice cream" Write a statement that converts this string into the list ["cookies", "milk", "fudge", "cake", "ice cream" and displays them. IN Parrow_forward
- B) Create a program that asks the user to enter a series of positive numbers. The program should store the positive numbers in a list. When the user enters a negative number, the program should stop asking the user to enter numbers. The program should display the following data: - The lowest number in the list. - The highest number in the list. - The average of the numbers in the list. : use python codearrow_forwardIN PYTHON PLEASE!!! (Find the index of the smallest element) Write a function that returns the index of the smallest element in a list of integers. If the number of such elements is greater than 1, return the smallest index. Use the following header: def indexOfSmallestElement(lst): Write a test program that prompts the user to enter a list of numbers, invokes this function to return the index of the smallest element, and displays the index.arrow_forwardPython program that reverses the order of five numbers stored in a list. The program should first print the five numbers stored in the list. Next, the program passes the list to a function where the numbers are reversed. Finally, the main program should print the reversed numbers. Make sure the file Reverse.py is selected and open. Write the Python statements as indicated by the comments. Execute the program by clicking the Run button at the bottom of the screen code: """ Reverse.py - This program reverses numbers stored in an array. Input: Interactive. Output: Original contents of array and the reversed contents of the array. """ # Write reverseArray function here. numbers = [9, 8, 7, 6, 5] # Print contents of array. # Call reverseArray function here. # Print contents of reversed array.arrow_forward
- IN PYTHON: DO NOT USE ENUMERATE OR NUMPY Write the following function that returns the location of the largest element in a two-dimensional list: def locateLargest(a): The return value is a one-dimensional list that contains two elements. These two elements indicate the row and column indexes of the largest element in the two-dimensional list. Write a test program that prompts the user to enter a two dimensional list and displays the location of the largest element in the list. Sample Run: Enter the number of rows in the list: 3 Enter a row: 20.6 40 1 4 Enter a row: 5.5 3 42 4.5 Enter a row: 46 32 4.4 12.1 The loacation of the largest element is at (0,2)arrow_forwardProblem Statement: Design a program that asks the user to enter a series of 10 integers. The program should store the numbers within a list and then calculate and display the following data: the lowest number on the listthe highest number on the listthe sum of the numbers on the list, andthe average of the numbers on the list--------------------------------------------------------------------------------------------------- Details: Develop a function for each of the following: A function to determine the lowest number on the list The function receives the list as an argument The function returns the lowest number on the list back to the main function The lowest number then is displayed within the main function A function to determine the highest number on the list The function receives the list as an argument The function returns the highest number on the list back to the main function The highest number then is displayed within the main function A function to determine the sum…arrow_forwardRead the string variables visitedListName, place1, place2, and place3 from input, assuming that the list's name contains multiple words and each place visited is a single word. The first input line contains the list's name and the second input line contains the places visited. Ex: If the input is: Countries I've visited Qatar Zambia Malta then the output is: Countries I've visited: Qatar Zambia Malta #include <iostream> #include <string> using namespace std; int main() { string visitedListName; string place1; string place2; string place3; /* Your code goes here */ cout << visitedListName << ":" << endl; cout << place1 << endl; cout << place2 << endl; cout << place3 << endl; return 0; }arrow_forward
- Assume the file popular_names.txt contains the 400 most popular names given to children born in the United States from the year 2000 through 2009. The file contains 400 lines, with one name per line. Write a Python program that reads the contents of the file into a list. The program should display the following string to prompt the user to enter a name: 'Entet a name: ' The program should then display a message indicating whether the name is among the most popular. If the name is found in the list, the program should display the following message: 'That was a popular name between 2000 and 2009.' If the name is not found in the list, the program should display the following message: 'That was not a popular name between 2000 and 2009.' Look carefully at the samples given. In the first example, the user enters a name that is found in the list. In the second example, the user enters a name that is not found in the list. Carefully notice the wording of the messages and the placement…arrow_forwardAssume list1 references a list. After the following statement executes, list1 and list2 will reference two identical but separate lists in memory: list2 = list1, True or Falsearrow_forwardB) Create a program that asks the user to enter a series of positive numbers. The program should store the positive numbers in a list. When the user enters a negative number, the program should stop asking the user to enter numbers. The program should display the following data: - The lowest number in the list. - The highest number in the list. - The average of the numbers in the list. write the code in pythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education