Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7, Problem 2PE
Program Plan Intro
- • Import the needed package “random”.
- • Declare a function named “generateLotteryNumber()”.
- ○ Declare an empty list “lotteryNumberList”.
- ○ Use a “for” loop to generate 7 random numbers in the range 0 to 9 using “random” and append each random number to the empty list using “append()” function.
- ○ Use another “for” loop to iterate through the “number” till the end of the list “lotteryNumberList” to print the content in the list.
- • In the “main()” function:
- ○ Call the function “generateLotteryNumber()”.
- • Finally, call the “main()” to execute the program.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
/*
PYTHON ONLY AND PLEASE COMMENT CODE
1.
A) write a For loop that iterates through a list of products (any number of products) that are sold in a store and prints them. [examples: fan, fridge, freezer, washer, etc.].
b) copy the code from a) and use the same loop to add more products(any)to the list. You must use list methods to add.
c) Copy the code from c), and search for a specific product (any), if the product is found the loop is terminated. Make sure to use else in the for loop.
d) Create an empty dictionary, then add 4 entries (the key is a word, the value is word’s frequency in a book). [example: {‘street’: 23}].
e) Create a for loop to access the entries from d) and print the keys and values.
f) Copy the code from e) and search for a specific key in the dictionary and prints its value. The program prints a message “ the {key} is not found”, if the key does not exist.
1. Total SalesDesign a program that asks the user to enter a store’s sales for each day of the week. Theamounts should be stored in a list. Use a loop to calculate the total sales for the week anddisplay the result.
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
- Lottery Number Generator Problem Design a Flowchart that generates a 7-digit lottery number. The program should have an integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element. Then, write another loop that displays the contents of the array.arrow_forwardMultiple Choice Identify the choice that best completes the statement or answers the question. 1. A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the number of elements in the list that have a value greater than 100. The algorithm uses the variables count and position. Steps 3 and 4 are missing. Step 1: Set count to 0 and position to 1. Step 2: If the value of the element at index position is greater than 100, increase the value of count by 1. Step 3: (missing step) Step 4: (missing step) na viliog dbod cour pot Step 5: Display the value of count. Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended? Step 3: Repeat step 2 until the value of count is greater than 100. Step 3: Repeat step 2 until the value of position is greater than n. a. c. Step 4: Increase the value of position by Step 4: Increase the value of count by 1. 1. b. Step 3: Increase the value of position by d. Step 3:…arrow_forwardC# Gas Station Program: Write a program that allows the users to select items that are for sale in a gas station. Candy, Soda, Pizza, Muffins and the list goes on. Keep a running total of the items ordered (loop until user is done ordering) when they are done ordering items, output the total salessales.arrow_forward
- Max and Min (by Lists) Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the numbers at the end when the user enters "done" . Write the program to store the numbers the user enters in a list and use the max() and min() functions to compute the maximum and minimum numbers after the loop completes. Enter a number: 6 Enter a number: 2 Enter a number: 9 Enter a number: 3 Enter a number: 5 Enter a number: done Maximum: 9.0 Minimum: 2.0arrow_forwardCENGAGE MINDTAP Programming Exercise 9-2A | Instructions The mean of a list of numbers is its arithmetic average. The median of a list is its middle value when the values are placed in order. For example, if an ordered list contains 1, 2, 3, 4, 5, 6, 10, 11, and 12, then the mean is 6, and their median is 5. Write an application that allows you to enter nine integers and displays the values, their mean, and their median. An example of the program is shown below: Enter number 6 12 Enter number 7 14 Enter number 8 16 Enter number 9 18 You entered: 2, 4, 6, 8, 10, 12, 14, The mean is 10.0 and the median is 10 YE ا... | 16, 18 MeanMedian.java 1 +arrow_forwardc++ double linked list program where you need to create a playlist of songs and you need to loop the songs in the playlistarrow_forward
- Q1/ Devolve an algorithm that allows the user to enter the count of numbers in a list followed by these numbers. The algorithm should find and output the even and odd numbers in the list.arrow_forwardPressure Unit ConversionsWrite a program that converts a value in Torr into Kilopascal. Both of these are units used to measure pressure. Use the following formula to covert Torr to Kilopascal: 1 Torr = 132/1000 KiloPascalsYour Program must use a loop to display a table of the quantities in Torr from 1 to 10 and their KiloPascal equivalents.arrow_forwardAnswer correctly and fast else downvote gurranteed Create a program that makes a grocery list. You will need an array of strings. You don’t know how many items will be on your list. Simple problem: User tells you how many items, then tells you the items. You display the items for the user. More complex problem: User tells you how many items, then tells you the items. You display the items for the user. At the end of the program, write the grocery list to a text file called grocery.txt. Even more complex problem: If grocery.txt exists, read it into an array and display to the user. User then tells you how many more items, and then tells you the items. You display all the items for the user. At the end of the program, write the grocery list to a text file called grocery.txt. Start with the simple program, move toward the complex one.arrow_forward
- Create a triangle of summations Example Input: [2,4,5,7,9] Start with a list of numbers Create a list of the summation of the first two numbers, then the next two. Output: [85] [36, 49] [15, 21, 28] [6, 9, 12, 16] [2, 4, 5, 7, 9] Continue building new lists until there is only 1 number left Be sure to print your list during each iteration of your function MUST USE RECURSION!!arrow_forwardPythonarrow_forwardLab Goal : This lab was designed to teach you more about list processing and algorithms.Lab Description : Write a program that will search through a list to find the smallest number and the largest number. The program will return the average the largest and smallest numbers. You must combine variables, ifs, and a loop to create a working method. There will always be at least one item in the list.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning