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
Yahtzee!
Yahtzee is a dice game that uses five die. There are multiple scoring abilities with the highest being a Yahtzee where all five die are the same. You will simulate rolling five die 777 times while looking for a yahtzee.
Program Specifications :
Create a list that holds the values of your five die.
Populate the list with five random numbers between 1 & 6, the values on a die.
Create a function to see if all five values in the list are the same and IF they are, print the phrase "You rolled ##### and its a Yahtzee!" (note: ##### will be replaced with the values in the list)
Create a loop that completes the process 777 times, simulating you rolling the 5 die 777 times, checking for Yahtzee, and printing the statement above when a Yahtzee is rolled.
When you complete the project please upload your .py file to the Project 2 folder by the due date.
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
- In Python pleasearrow_forwardpaython programing question Write a program that creates a list of N elements (Hint: use append() function), swaps the first and the last element and prints the list on the screen. N should be a dynamic number entered by the user. Sample output: How many numbers would you like to enter?: 5 Enter a number: 34 Enter a number: 67 Enter a number: 23 Enter a number: 90 Enter a number: 12 The list is: [12, 67,23, 90, 34]arrow_forward*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_forward
- Create 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_forwardOCaml Code: Attached are the instructions. Make sure to read the instructions carefully and write your own test cases to make sure the code works. Make sure to include a screenshot of the correct code with the test cases that is used along with the output of the code being passed.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_forwardPhyton: Program 6: Write a program that allows the user to add data from files or by hand. The user may add more data whenever they want. The print also allows the user to display the data and to print the statistics. The data is store in a list. It’s easier if you make the list global so that other functions can access it. You should have the following functions: · add_from_file() – prompts the user for a file and add the data from it. · add_by_hand() – prompts the user to enter data until user type a negative number. · print_stats() – print the stats (min, max, mean, sum). You may use the built-in functions. Handling errors such as whether the input file exist is extra credit. To print a 10-column table, you can use the code below: for i in range(len(data)): print(f"{data[i]:3}", end="") if (i+1)%10==0: print() print() Sample run: Choose an action 1) add data from a file 2) add data by hand 3) print stats 4)…arrow_forwardOCaml Code: Please read the attached instructions carefully and show the correct code with the screenshot of the output. I really need help with this assignment.arrow_forward
- Write 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_forwardPython 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_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr