Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 7, Problem 4TF
Explanation of Solution
Copying lists:
- • In Python, to copy a list to another list, simply assign the list to be copied to another list
- • Both the lists will be identical as they refer to the same object in the memory.
Example program:
#Create a list of strings
slist1 = ['Jack', 'John', 'James']
#Copy slist1 to slist2
slist2 = slist1
#Print the slist1
print(slist1)
#Print the slist2
print(slist2)
#Change a string in slist2
slist2[1] = 'Jacob'
#Print the slist1
print(slist1)
#Print the slist2
print(slist2)
Sample output:
['Jack', 'John', 'James']
['Jack', 'John',...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Assume list1 references a list. After the following statement executes, list1 and list2 willreference two identical but separate lists in memory:list2 = list1 (T/F)
Alert - don't use AI
In Python please
Chapter 7 Solutions
Starting Out with Python (4th 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.10 - Prob. 26CPCh. 7.10 - Prob. 27CPCh. 7.10 - Prob. 28CPCh. 7.10 - Prob. 29CPCh. 7.10 - Prob. 30CPCh. 7.10 - To create a bar chart with the bar function, what...Ch. 7.10 - Assume the following statement calls the bar...Ch. 7.10 - Prob. 33CPCh. 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. 11PECh. 7 - Prob. 12PECh. 7 - Magic 8 Ball Write a program that simulates a...Ch. 7 - Expense Pie Chart Create a text file that contains...Ch. 7 - 1994 Weekly Gas Graph In the student sample...
Knowledge Booster
Similar questions
- *Coding language is Python Write a program that opens the productsales.txt file and reads the sales into a list. The program should output the following information, in this order: The total of all sales in the list The average of all sales in the list The lowest sale in the list The highest sale in the list NOTE: Your program should include at least one user-defined function, in addition to the main function. 4147 1594 2235 8433 10000 129 5555 7030 9764 7465 1111 4444 8954 2243 2895 1436 4978 5486 1436 9846 4789 8456 2497 2280 6375arrow_forwardCreate a soda beverage shopping cart program using C++ implementing the following: Linked List - this will be used as the user's cart. This is where the items that the user will purchased are stored here before checking them out. Array - use arrays to store user's stored products. Pointers Functions - Make sure that the rogram will have user-defined functions (e.g.: function for adding nodes, function for displaying the cart, etc.) The program must have a menu where the user can select an action (e.g. Select product, View cart, Check out, etc.) Soda options: Coca-Cola, Pepsi, Sprite, Royal, Mountain Dew Must implement Developer name before the program exits. Please show the entire code and final output.arrow_forwardCreate a soda beverage shopping cart program using C++ implementing the following: Linked List - this will be used as the user's cart. This is where the items that the user will purchased are stored here before checking them out. Array - use arrays to store user's stored products. Pointers Functions - Make sure that the rogram will have user-defined functions (e.g.: function for adding nodes, function for displaying the cart, etc.) The program must have a menu where the user can select an action (e.g. Select product, View cart, Check out, etc.) Soda options: Coca-Cola, Pepsi, Sprite, Royal, Mountain Dew Tabular Format: In the table, you must include the code for each soda options, their price and quantity The program must look like this: Hi! Welcome to ABC GoDrink! Here are the drinks that we offer: CODE PRODUCT SRP a Coca-Cola 24.99 b Pepsi 22.99 c Royal 24.99 d Sprite 24.99 e Mountain Dew 22.99 Menu Select a product. View My Cart and Proceed to Check-Out…arrow_forward
- Ex1: a) Write a function for the user to enter a positive integer n with a value between 10 and 1000. If entered correctly, the function generates a list containing n random values that do not overlap between 1 and 5000 and the function returns the newly created list. Conversely, if entered incorrectly, the program will ask to re-enter until it is correct. Cases where n is considered incorrect:(i)- If the user enters a non-integer data type (like string, float, bool, ...)The program will display the error message 'Must enter a positive integer. Requires re-entry'.(ii)- If the input value is of the correct integer data type but the value is not in the range10 to 1000, the program gives the error 'Only values between 10 and 1000. Re-enter required'.Installation requirements: must use the try ... except statement to handle possible exceptionsin the program. b) Write a function that lists the amicable numbers in the list just created in a) (If there are no amicable numbers in the list,…arrow_forwardWrite a function that returns the greatest common divisor (GCD) of integers in a list. Use the following function header:def gcd(numbers):Write a test program that prompts the user to enter five numbers, invokes the function to find the GCD of these numbers, and displays the GCD.arrow_forwardThis.arrow_forward
- Python Programming Write a program that asks the user to enter a series of ten numbers. The program is to store the numbers in a list: Write a function that accepts the created list as an argument and displays the following: The lowest number in the list The highest number in the list The total of the values in the list The average of the numbers in the list Ask the user to enter a number, this number will be used in the following step. Write a function that accepts the created list and the number as arguments. The function is to display all the numbers in the list that are greater than then number.arrow_forwardA-Language- Python Write a fully functioning program that correctly uses a list, reads, and writes from/to an external file. Megan owns a small neighborhood coffee shop, and she has fifteen employees who work as baristas. All of the employees have the same hourly pay rate. Megan has asked you to design a program that will allow her to enter the number of hours worked by each employee and then display the amounts of all the employees’ gross pay. You determine that the program should perform the following steps: The text that is in the file is stored as one sentence. Incorporate the code that reads the file’s contents and calculates the following: total number of words in the file total average number of words per sentence total number of characters in the file total average number of characters per sentence Use function(s) to accommodate this word and character analysis of the file B For each employee: Get the employee name from the file named employee_names.txt (attached in…arrow_forwardFUNCTION ONE: MAINO In this lab we will create three functions. The first will be called main. Main will simply be the first function executed and will call the other two funetions. It will take in no arguments and will only create an empty list and call the other two functions. FUNCTION TWO: GETDATAO Getdata() will take in a list and then prompt the user to enter a song as a string in the format of song-band. You may assume the user will correctly enter this data. These songs will be appended to our list. The user can continue entering songs until they enter "exit". FUNCTION THREE: PLAYRANDOMO PlayRandom() will take in a list. It will then generate a random number and use it as index to select a random song to print "Now Playing: RandomSongHere". SAMPLE OUTPUT Enter a song title and band (song-band) or exit to quit: I Found- Amber Run Enter a song title and band (song-band) or exit to quit: Bark At The Moon-Ozzy Osbourne Enter a song title and band (song-band) or exit to quit: Real…arrow_forward
- static List<String> findWinners(String pattern, int minLength, boolean even, Stream<String> stream) This function will receive a stream of strings and it will return a sorted list of strings that meet all of the following criteria: They must contain the pattern The strings length must be equal to or greater than the min length number The strings length must be an even or odd number This Function must take no longer 10000 milliseconds to return. pattern - A pattern that all the strings in the list returned must containminLength - The length that all the strings in the list returned must be equal to or greater thaneven - True if even false if odd. Denotes a condition that all the strings in the list returned must have a length that is even or odd.stream - A stream of strings to be filteredreturn - A list of strings that meets the criteria outlined above sorted by their length from small to largearrow_forwardpython program plzarrow_forward??.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr