Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Overview This assignment will give you more experience on the use of 1. string:s 2. conditionals 3. iteration 4. input/output to create a Typing

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Assignment Overview This assignment will give you more experience on the use of 1. string:s 2. conditionals 3. iteration 4. input/output to create a Typing Game Assignment Background This project asks you to write a program to implement a typing game. In this game, a user earns rewards by quickly typing the correct words shown by the program in a limited time Python modules required for this project: . import string import time . from cse231_random import randint ure Step 1 The program starts by prompting the user to choose a hardness level - Enter "E" or "e" for the Easy level Enter "M" or "m" for the Medium level - Enter "H" or "h" for the Hard level - Hits 'Enter' key for the defaul level. The default level is Easy - "Q" or q' to quit the game and stop this program If the user enters anything else, you will print out an error message and continually prompt until the user input is valid Step 2 After the user chooses the hardness level, the program will repeatedly . generate a random string with a random length of characters. The length depends on the chosen hardness level prompt the user to enter the correct string. A correct string should contain the same characters in the same order as generated by your program. It sh within a time interval. The interval depends on the hardness level (See the Rules to set the timeout interval below) . ould also be entered user wins rewards if he gets the correct word within the limited time, or fails and get zeros rewards otherwise . Step 2 will be terminated either when the user fails on entering a correct string (enters the wrong string or timeout) the user continuously wins the game 10 times . . (Hint: use a for loop for step 2) After step 2 is complete (either the user enters 10 correct inputs, or fails in the middle) Display the total time spent and the total number of games played in this round Calculate the rewards earned in the current round by the user o For Easy level, the reward for one correct input string is 1 * the number of characters . in that string. (For example, if the user chooses the Easy level, and inputs 3 times with the correct string, each string has length 4, 6, 5, then he wins 1 * 4+ 1 61*5 rewards in this round.) o For Medium level, the reward for one correct input string is 2 the number of characters in that string For Hard level, the reward for one correct input string is 3* the number of characters in that string o Step 3 Calculate the accumulated rewards earned by the user. Each user has 0 rewards at the beginning of the program Example: if a user first chooses the easy level and wins 15 rewards, then chooses the hard level and wins 30 rewards, his total reward after the second run should be 15 3045 After step 3, the program will go back to step 1 and prompt the user to choose the hardness level for the next round. If the user quits the game, the program outputs the total number of games played in all rounds and the accumulated rewards earned by the user (Hint: your game contains a big while loop inside which we repeat step 1 - step 3.) Example: if a user first chooses the easy level, enters 3 correct inputs and wins 15 rewards then chooses the hard level, enters 2 correct inputs and wins 30 rewards, the program should output: Your final total: 5/20 Your total reward: 45 Rules to set the timeout interval .For the Easy round, the timeout interval t is 10 seconds For the Medium round, the timeout interval t is 9 seconds For the Hard round, the timeout interval t is 8 seconds Algorithm to check if a user is running out of the time 1. 2. 3. t2 - t1 is the time elapsed. If the elapsed time is larger than t, the user will not get any Before we prompt the user for a correct input string, we use the time.time0 function to get the current time t1 in seconds since the Epoch (since January 1, 1970) After the user enters a string, we again use the time.time0 function to get the current time t2. reward for the string he inputs Rules to check if an input string is correct: A correctly entered string should contain the same letters and the same punctuation in the correct order as the one generated by your program. However, there are some additional rules to be .For Easy level, the inputs are case-ignorant. For example, if the program generates a .For Medium and Hard level, the inputs are case-sensitive. For example, if the program taken care of string as 'Hello', your input such as hello', 'hELLo', etc., will be considered as correct. generates a string as 'Hello-!, your input such as hello!', 'hELLo-!', etc., will be considered wrong, but "Hello!" will be correct. For Easy level, we allow users to enter spaces even though the generated string does not contain spaces. For example, if the program generates a string as 'Hello', you can input He o as a correct answer For Medium and Hard level, spaces are not allowed . Rules to generate random words with a random length . How to choose the random length o For Easy level, the random length n should be bounded in the range 33ns5 o For Medium level, the length n is bounded by 6Sns 10 o For Hard level, the length n is bounded by 11sns 15. Hints - use the random.randint(lower_bound, upper_bound) function to help you generate a random integer In the Python console, type the following commands to help you understand what the random.randint() function does >>Import random >>help(random.randint) How to generate a random string given the length of the string . Allowed characters include For Easy level: all English letters (26 lower case letters and 26 upper case letters). Use ALPHABET_EASYstring.ascii_letters For Medium and Hard levels: all English letters and all punctuation. Use ALPHABET-string.ascii_letters + string.punctuation Alright. Now we have an alphabet; how can we generate a random string with length n (n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions