Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSE 231 Spring 2019 Programming Project 03 Edit: 1/22: default level clarified, specifically default is Easy This assignment is worth 20 points (2% of the

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

CSE 231 Spring 2019 Programming Project 03 Edit: 1/22: default level clarified, specifically default is "Easy" This assignment is worth 20 points (2% of the course grade) and must be completed and turned in before 11:59 PM on Monday, January 28, 2019 Assignment Overview This assignment will give you more experience on the use of 1. strings 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 Procedure 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" - Hits 'Enter key for the default level. The default level is Easy - "Q" or 'q' to quit the game and stop this program or "h" for the Hard level 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 should also be entered within a time interval. The interval depends on the hardness level (See the Rules to set the timeout interval below) 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: 1530 45 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 Alright. Now we have an alphabet; how can we generate a random string with length n (nN) from that? The answer is, we can use a forloop to iterate n times. Each time, we randomly choose one character from the alphabet using an index that we randomly generate Hints: use random.randint(lower bound, upper bound) to help you generate an index. Please be careful about the lower_bound and upper_bound. Your index should be in the range of (0, N 1), where N is the length of your alphabet. A pseudo-code for generating a random string with length n is given below: alphabet # Get the alphabet N-# get the length of the alphabet N-# get the length of the random string you want to generate word' # an empty string for loop (iterate n times) Index- random.randint(xx, xx) char-alphabet[index Concatenate char to the end of word Assignment Deliverable The deliverable for this assignment is the following file proj03.py the source code for your Python program Be sure to use the specified file name and to submit it for grading via the Mimir before the project deadline Assignment Notes 1. 2. 3. To clarify the project specifications, sample output is appended to the end of this document Items 1-6 of the Coding Standard will be enforced for this project. We provide a proj03.py program for you to start with. It outlines where to place your while loop (notice how input is prompted before the loop and at the bottom of the loop) with a for loop inside Make sure that the cse231_random.py program file is in the same folder/directory as your program and that you uncomment the correct VALUES line for the appropriate test-there is a separate set of VALUES for each test. 4. 5. You are not allowed to use advanced data structures such as list, dictionaries, classes. 6. Hard coding will result in a score of zero. That is, if you tailor your solution to only work for the test cases instead of working for general cases, you will receive a score of zero Reminder: programming projects are individual assignments, not to be done collaboratively with other students. See the syllabus for details 7. Test 1 P1ase ch se the difficulty level: Ele) for Easyi MIm) or Medium; Hh) for Hard; Hit "Enter" for Default; 21q) to quiti Level: e Level [E,gm 1/10] Enter this string: jbGl jbGl Good job! You spent .0 of 10 seconds entering string [jbGl][jbGL] Level [E], game [21/010] Enter this string: tlpks tlpks Good job! You spent 0.0 of 10 seconds entering string tlpks] [tlpks] Level [E, game [3]/[10] Enter this string: hVWT Good job! You spent 0.0 of 10 seconds entering string [hVWT] [hVWT] Level [E, game [41/I10] Enter this string: CUn Good job! You spent 0.0 of 10 seconds entering string [Cn] [CUn] Level [E], game 51/[10] Enter this string: goiv goiv Good job! You spent 0.0 oi 10 seconds entering string [goiV] [gOiv] Level E, game [6/[10] Enter this string: rTY rTY Good job! You spent 0.0 of 10 seconds entering string [rTY][rTY) Level [E, game 71/[10] Enter this string: HKsxY HKsxY Good job! You spent 0.0 of 10 seconds entering string [HKsxY [HKsxY] Level IE], game [a]/(10] Enter this string: Izeu Izeu Good job! You spent 0.0 of 10 seconds entering string [Izeu] [Izeuj Level E, game [9]/I10] Enter this string: JKm JKm Good job! You spent 0.0 of 10 seconds entering string JKm JKm) Level [E], game 10)/101 Enter this string: Dk JT DkJJ Good job! You spent 0.0 of 10 seconds entering string [DkJJ][DkJJ] Result of this game is 10/10 Total time for this game: 0.0 Please choose the difficulty level: Ele) for Easy; Mim) tor Medium; Hh) for Hard; Hit "Enter" for Default; 21q) to quit; Level:q Your final total: 10/10 Your total reward: 39 Test 2 Please choose the difficulty level: E e) for Easy M Im) for Medium; Hh) for Hard; Hit "Enter" for Default; OIq) to quit: Level x Difficulty level not recognized Please choose the difficulty level: Ele) for Easyi M lm for Medium; Hlh) tor Hard; Hit "Enter" for Default; QI) to quit; Level: m Level [M], game [1/[10] Enter this string: !a.j Good job! You spent .0 of 9 seconds entering string [-1a."J-] [-1a -] Level [M], game [2]/[10] Enter this string: FW:y-V? Good job! You spent 0.0 of 9 seconds entering string [FW:y-V?] [EW:y-v?] Level [M], game [3]/[10] Enter this string: e FCmSL alb2c3 Incorrect. Result of this game is 2/10 Total time for this game: 0.0 Please choose the difficulty level: Ele) for Easyi M(m) for Medium; Hh) for Hard; Hit "Enter" for Default; Q(q) to quit; Level: q Your final total: 2/10 Your total reward: 30 Test 3 Please choose the difficulty level: E le) for Easyi M m) for Medium; H (h) for Hard; Hit "Enter" for Defaulti 21q) to quit; Level: h Level [H, game 1/10] Enter this string: S(N.p"g(Mz\EAX Good job You spent 0.0 of 8 seconds entering string Level H, game [2/[10] Enter this string: J/t=0\ BMzd Good job! You spent 0.0 of 8 seconds entering string Level [H, game [3/[10] Enter this string: !WBJvT- Good job! You spent 0.0 of 8 seconds entering string [@o' ] { ! WBJyT-W] [ @o' ] !WBJ v'I'=W ] Level [H], game [4]/[10] Enter this string: 'RJys K-F, WSO XXX2 Incorrect. Result of this game is 3/10. Total time for this game: 0.0 Please choose the difficulty level: Ee) for Easy: M(m) fr Medium; Hh for Hard; Hit "Enter" for Default; Iq) to quit: Level: q Your final total: 3/10 Y ur total rewa rd: 114 Test 4 Please choose the difficulty level: Ele) for Easy; MIm) for Medium; H(h) for Hard Hit "Enter" for Default; QIq) to quit; Level: h Level H, game 1/[10] Enter this string: u' cqvt (*WGE?K Good job! You spent 0.0 of 8 seconds entering string Level [H, game [2)/[10 Enter this string : Qon_g#B1XP gosn_g #BlXP Good job! You spent 0.0 of 8 seconds entering string Level H], game [3]/[10] Enter this string: CwyUDua;"re:: xyzz Incorrect Result of this game is 2/10. Total time for this game: 0.0 Please choose the difficulty level: Ele) for Easy; M Im) for Medium; Hth) for Hard; Hit "Enter" for Default; 01q) to quit; Level: e Level [E], game [1/[10] Enter this string: BLCph BLCph Good job! You spent 0.0 of 10 seconds entering string BLCph [BLCph] Level [E], game [21/010] Enter this string : khD Test 4 Please choose the difficulty level: Ele) for Easy; MIm) for Medium; H(h) for Hard Hit "Enter" for Default; QIq) to quit; Level: h Level H, game 1/[10] Enter this string: u' cqvt (*WGE?K Good job! You spent 0.0 of 8 seconds entering string Level [H, game [2)/[10 Enter this string : Qon_g#B1XP gosn_g #BlXP Good job! You spent 0.0 of 8 seconds entering string Level H], game [3]/[10] Enter this string: CwyUDua;"re:: xyzz Incorrect Result of this game is 2/10. Total time for this game: 0.0 Please choose the difficulty level: Ele) for Easy; M Im) for Medium; Hth) for Hard; Hit "Enter" for Default; 01q) to quit; Level: e Level [E], game [1/[10] Enter this string: BLCph BLCph Good job! You spent 0.0 of 10 seconds entering string BLCph [BLCph] Level [E], game [21/010] Enter this string : khD ikhD Good job! You spent 0.0 of 10 seconds entering string [ikhD] ikhD] Level [E], game [3]/[10] Enter this string: Mslb Mslb Good job! You spent 0.0 of 10 seconds entering string [Mslb] [Mslb] Level E, game [41/I10] Enter this string IziJy ZJy Good job! You spent 0.0 of 10 seconds entering string [IzJy] [1ziJy] Level [E], game [51/[10] Enter this string: mOP mOP Good job! You spent 0.0 oi 10 seconds entering string [mOP] [moP] Level [E],game 6]/[10] Enter this string: fjTkd fjTkd Good job! You spent 0.0 of 10 seconds entering string [fjTkd] [fjTkd] Level [E, game [7/[10] Enter this string: LNKFE LNKPf Good job! You spent 0.0 of 10 seconds entering string [LNKFf [LNKEf] Level [E], game [8]/[10] Enter this string: Xckw Xckw Good job! You spent 0.0 of 10 seconds entering string [XekW] [Xcki] Level E, game [91/[10] Enter this string: BeSz BeSz Good job! You spent 0.0 of 10 seconds entering string [BeSz] [BeSz] Level [E, game [10]/[10] Enter this string: psrm psm Good job! You spent 0.0 of 10 seconds entering string lpsm] [psm] Result of this game is 10/10 Total time for this game: 0.0 Please choose the difficulty level: E e) for Easy MIm) for Medium; Hh) for Hard; Hit "Enter" for Defaulti QIg) to quit; Level m Level M, game [1]/[10] Enter this string: mrR' 'Sa) Good job! You spent 0.0 of 9 seconds entering string [mrR ''Sa)] [mrR''Sa }] Level M, game [21/[10] Enter this string: UAGIUrzj Good job! You spent 0.0 of 9 seconds entering string [U#GIUrzj] [U#G [Urzj] Level [M, game 3/[10] Enter this string: Tb!$

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

Step: 3

blur-text-image

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

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

Describe the advantages and disadvantages of sole proprietorships.

Answered: 1 week ago