Question: (Python) How would I start writing this code? What variables and strings etc would I have to write in order to write the code? First,
(Python) How would I start writing this code? What variables and strings etc would I have to write in order to write the code?










First, your software needs to be able to run for an undetermined amount of time, only ending when the user requests that it does. This allows for your program to store its data as it runs - unfortunately, we're not at the point yet in the semester where we can create and save files locally. It also needs to ask the user what they want to do next, in the form of a question (with intended text responses.) Specifically, your code needs to use a while loop to run infinitely, only ending the software (and thus the loop) when the user says stop and continuing on otherwise. At this point, your code should look something like this when it runs: Enter STOP to finish. Enter STOP to finish. Enter STOP to finish. where are you Enter STOP to finish. we've got some work to do now Enter STOP to finish. STOP > Note that you need something (anything, really) temporarily inside your while loop in order to get this behavior - otherwise, you'll get an error. We'll be adding stuff into the loop in the next few steps. Also, if you design this cleverly, you can simply hit the ENTER key to keep it going - this is what's happening in the first line. For clarity, the >>> in the last line is how Thonny indicates that the program finished running, while the symbol just represents an empty line where the user only hit the ENTER key. After asking if it should continue, your program next needs to ask the user what they want to do. The options here need to be ADD, GAMES, PLAYERS, and RECORDS. Your code should now resemble this when running: Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) games Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) players Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) records Enter STOP to finish. stop Note that, while I typed my inputs in lowercase, it seems to have stored them as uppercase strings. This can be a helpful design choice, and I recommend checking out the . upper () function for strings. Step 3: Letting the User Add Records Now things get interesting! First, we'll add the functionality that occurs when the user types add, as the rest rely on what we do here. After this step, your code needs to be able to do the following: - Ask the user which game the record is for. - Ask for the speedrun's player, its runtime (in seconds), and the date that it happened. Be aware that your code needs to be able to store several record attempts for the same game; for simplicity, we will assume that they are entered in temporal order, i.e., the last one entered is the most recent and thus is the current record. As a reminder, your code needs to keep track of all records (for all games) entered during the program's runtime, so you'll likely need a variable containing all of the records per game, and each game will then hold a set of its own records. To check if your code is working, you temporarily can print the variable holding all of the data. If you do, it should resemble this when running: Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Jim-Jam What's the speedrun time in seconds? 3175 When did this speedrun occur? 5-18-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Luz What's the speedrun time in seconds? 3143 When did this speedrun occur? 10-15-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pac-Man What's the players name? Garrett B. Ferguson What's the speedrun time in seconds? 39 When did this speedrun occur? 31122 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, RECORDS) add What game is this for? Knack 2 What's the players name? Anya What's the speedrun time in seconds? 12826 When did this speedrun occur? 9-26-20 Enter STOP to finish. stop Step 4: Printing All Games in the Database Next, we add the functionality for when the user types add. When they do this, we need to print all of the games currently in the database. Your code cannot simply print out the containers holding the data it needs to somewhat nicely print out each game title. This can be on the same line or on a different line, either works as long as you aren't just printing the container (which typically has additional visual artifacts that we don't want the user to see.) If done correctly, your program should now resemble this when running, Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Jim-Jam What's the speedrun time in seconds? 3175 When did this speedrun occur? 5-18-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Luz What's the speedrun time in seconds? 3143 When did this speedrun occur? 10-15-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pac-Man What's the players name? Garrett B. Ferguson What's the speedrun time in seconds? 39 When did this speedrun occur? 3-11-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Knack 2 What's the players name? Anya What's the speedrun time in seconds? 12826 When did this speedrun occur? 9-26-20 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) games Undertale Pac-Man Knack 2 Enter STOP to finish. stop Step 5: Printing All Players in the Database If the user instead types players, we need be able to print out the names of all players in the database across all games. As far as quality of life goes, it does not look very nice if we have multiple copies of the same person's name in our printout, so your code must print each person's name only once. This may require the (temporary) use of a specific container. For simplicity, assume that each person in the database has a unique name. If done correctly, your code should resemble this when it runs: Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Jim-Jam What's the speedrun time in seconds? 3175 When did this speedrun occur? 5-18-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Luz What's the speedrun time in seconds? 3143 When did this speedrun occur? 10-15-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pac-Man What's the players name? Garrett B. Ferguson What's the speedrun time in seconds? 39 When did this speedrun occur? 31122 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Knack 2 What's the players name? Anya What's the speedrun time in seconds? 12826 When did this speedrun occur? 9-26-20 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pikmin What's the players name? Luz What's the speedrun time in seconds? 3271 When did this speedrun occur? 12-19-19 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) players Luz Jim-Jam Garrett B. Ferguson Anya Enter STOP to finish. stop Lastly, if the user types in records, then we need to print all current records for each game in the database. Specifically, you should print out each game, and the information on its current record. For simplicity, you can simply print the container for this task if you used the appropriate one (which the example, admittedly, straight-up shows you.) If done correctly, your code should now (somewhat) resemble this: Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Jim-Jam What's the speedrun time in seconds? 3175 When did this speedrun occur? 5-18-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Luz What's the speedrun time in seconds? 3143 When did this speedrun occur? 10-15-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pac-Man What's the players name? Garrett B. Ferguson What's the speedrun time in seconds? 39 When did this speedrun occur? 3-11-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Knack 2 What's the players name? Anya What's the speedrun time in seconds? 12826 When did this speedrun occur? 9-26-20 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, RECORDS) add What game is this for? Pikmin What's the players name? Luz What's the speedrun time in seconds? 3271 When did this speedrun occur? 12-19-19 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) records Undertale: \{'player': 'Luz', 'runtime': 3143, 'date': '10-15-22'\} Pac-Man: \{'player ': 'Garrett B. Ferguson', 'runtime': 39, 'date': '3-11-22'\} Knack 2: \{'player ': 'Anya', 'runtime': 12826, 'date ': '9-26-20'\} Pikmin: \{'player ': 'Luz', 'runtime': 3271, 'date ': '12-19-19'\} Enter STOP to finish. stop Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Undertale What's the players name? Jim-Jam What's the speedrun time in seconds? 3175 When did this speedrun occur? 5-18-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, RECORDS) add What game is this for? Undertale What's the players name? Luz What's the speedrun time in seconds? 3143 When did this speedrun occur? 10-15-22 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, RECORDS) add What game is this for? Pac-Man What's the players name? Garrett B. Ferguson What's the speedrun time in seconds? 39 When did this speedrun occur? 31122 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Knack 2 What's the players name? Anya What's the speedrun time in seconds? 12826 When did this speedrun occur? 9-26-20 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) add What game is this for? Pikmin What's the players name? Luz What's the speedrun time in seconds? 3271 When did this speedrun occur? 12-19-19 Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) games Undertale Pac-Man Knack 2 Pikmin Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) players JimJam Garrett B. Ferguson Anya Luz Enter STOP to finish. What do you want to do? (ADD, GAMES, PLAYERS, REOORDS) records Undertale: \{'player ': 'Luz', 'runtime': 3143, 'date ': '10-15-22'\} Pac-Man: \{'player ': 'Garrett B. Ferguson', 'runtime': 39, 'date': '3-11-22' Knack 2: \{'player ': 'Anya', 'runtime': 12826, 'date ': '9-26-20'\} Pikmin: \{'player ': 'Luz', 'runtime': 3271, 'date ': '12-19-19'\} Enter STOP to finish. stop
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
