
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![Imagine you have a list top_scores list that can store only 5 numbers. Implement an algorithm in Python
that simulates a high score leaderboard in a game. The high score leaderboard tracks the top 5 scores that
have been posted so far. The behaviour of your program should mimic a leaderboard. Make suitable
assumptions if necessary but write them in your solution, Use the following starter code
import random
# empty list
top_scores= []
# loop that generates 50 random numbers
for i in range(50):
# generate a random number
rand_num = random.randint(0,100)
# add your code here
Your code should add the random number generated to the list top_scores only if the random number is
a new high score. A new high score is when the new number is among the top 5 scores observed so far.
Think in terms of a high score board in your favourite game.
Think in terms of what will happen when your list has less than 5 elements.
For example, if the list currently has [10,12,5,9,11] and the new number generated is 42, then 42 will
get added and the lowest number 5 will get replaced. so the list will be [10,12,42,9,11]. If the next
number generated is 3, nothing will happen as 3 is lesser than all the numbers in the list.](https://content.bartleby.com/qna-images/question/842ddfb5-3cba-4856-a7b3-78a95dca4dd5/e665f1ce-c5f3-44d1-9af9-6fd772e1c0f0/xmzc057_thumbnail.png)
Transcribed Image Text:Imagine you have a list top_scores list that can store only 5 numbers. Implement an algorithm in Python
that simulates a high score leaderboard in a game. The high score leaderboard tracks the top 5 scores that
have been posted so far. The behaviour of your program should mimic a leaderboard. Make suitable
assumptions if necessary but write them in your solution, Use the following starter code
import random
# empty list
top_scores= []
# loop that generates 50 random numbers
for i in range(50):
# generate a random number
rand_num = random.randint(0,100)
# add your code here
Your code should add the random number generated to the list top_scores only if the random number is
a new high score. A new high score is when the new number is among the top 5 scores observed so far.
Think in terms of a high score board in your favourite game.
Think in terms of what will happen when your list has less than 5 elements.
For example, if the list currently has [10,12,5,9,11] and the new number generated is 42, then 42 will
get added and the lowest number 5 will get replaced. so the list will be [10,12,42,9,11]. If the next
number generated is 3, nothing will happen as 3 is lesser than all the numbers in the list.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 2 images

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
- SivaNums are integers greater than 9. For example, the list [4, 15, 20, 2, -2, 0, 12] has 3 SivaNums. Use a 'for' loop and an 'if' statement to complete the Python function below so that it counts the number of SivaNums in any list. 1 def countSivaNums (numList): count = 0 6 return countarrow_forwardPYTHON without def function randomly generate numbers by rolling one die. That is, if your program rolls a die 6000 times, you should get approximately 1000 ones, 1000 twos, etc.? Use a list to count the number of times a die is rolled, given the user wants the die rolled N times. Example Execution #1 Input the number of rolls to make:NUMBER> 6Input the seed for the random number generator:SEED> 0Your 6 rolls follow:OUTPUT 1 occurred 1 timesOUTPUT 2 occurred 0 timesOUTPUT 3 occurred 1 timesOUTPUT 4 occurred 3 timesOUTPUT 5 occurred 1 timesOUTPUT 6 occurred 0 times Example Execution #2 Input the number of rolls to make:NUMBER> 600000Input the seed for the random number generator:SEED> 123456Your 600000 rolls follow:OUTPUT 1 occurred 100340 timesOUTPUT 2 occurred 100016 timesOUTPUT 3 occurred 100186 timesOUTPUT 4 occurred 99931 timesOUTPUT 5 occurred 99858 timesOUTPUT 6 occurred 99669 timesarrow_forwardThe chapter is nested lists Create code in python using for loops Thanks!arrow_forward
- Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Eachletter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue playing. Create a list to store the words, as follows:# Use any words you wishwords = ["write", "that", "program", ...]arrow_forwardIn Java: When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting the smallest value from all the values. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 30 50 10 70 65 the output is: 20 40 0 60 55 For coding simplicity, follow every output value by a space, even the last one. Your program must define and call a method:public static int getMinimumInt(int[] listInts, int listSize) import java.util.Scanner; public class LabProgram {/* Define your method here */ public static void main(String[] args) {/* Type your code here. */}}arrow_forwardThe function interleave_lists in python takes two parameters, L1 and L2, both lists. Notice that the lists may have different lengths. The function accumulates a new list by appending alternating items from L1 and L2 until one list has been exhausted. The remaining items from the other list are then appended to the end of the new list, and the new list is returned. For example, if L1 = ["hop", "skip", "jump", "rest"] and L2 = ["up", "down"], then the function would return the list: ["hop", "up", "skip", "down", "jump", "rest"]. HINT: Python has a built-in function min() which is helpful here. Initialize accumulator variable newlist to be an empty list Set min_length = min(len(L1), len(L2)), the smaller of the two list lengths Use a for loop to iterate k over range(min_length) to do the first part of this function's work. On each iteration, append to newlist the item from index k in L1, and then append the item from index k in L2 (two appends on each iteration). AFTER the loop…arrow_forward
- Can you use Python programming language to to this question? Thanksarrow_forwardplease explain pythonarrow_forwardpython LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forward
- IN PYTHON! finish the incomplete program by writing the code that can be placed below the #write the code. use loops to calculate the sums and avg of each row of scores in the list. the following output should be displayed. dont change any part of the code. OUTPUT: Average scores for students: Student # 1: 12.0 Student # 2: 22.0 CODE: students =[ [11, 12, 13], [21, 22, 23] ] avgs = [] # Write your code here: print('Average scores for students: ") for i, avg in enumerate (avgs): print("Student #', i + 1, ':', avg)arrow_forwardThe code fragment above contains a list of integers named my_list and a pair of counter-controlled loops. Once this code has been executed the variables qux and egg will have been assigned values. Let x denote the average those two values. If you were to create a new list that contains every integer in my_list that is greater than than x but also less than than x + 7 then what would be the length of that list? This question is internally recognized as variant 235. Q13) 1 2 3 4 5 6 7 8 none of the abovearrow_forwardIn Java: When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by subtracting the smallest value from all the values. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 30 50 10 70 65 the output is: 20 40 0 60 55 The 5 indicates that there are five values in the list, namely 30, 50, 10, 70, and 65. 10 is the smallest value in the list, so is subtracted from each value in the list. For coding simplicity, follow every output value by a space, including the last one. import java.util.Scanner; public class LabProgram {public static void main(String[] args) {/* Type your code here. */arrow_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