123456789012 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 444 41 42 0-0 0-0 00 from random import randint, choice import time import help instructions = """ARITHMETIC PLEASE You love number crunching don't you? Nice! so do we. Let's crunch some numbers then: First you select a level (i.e. number of operands in the expression) then we give you an arithmetic expression to solve based on your level -\nENJOY!!!\n""" user_data = ["\t\tSession Results: \n'] def get_level () -> int: """Get player level as input from stdin :raises ValueError :return n: user input value def generate_expr (n=2, *new_ops) -> tuple [str, float]: """Generates random arithmetic expression n number of operands :param n: Number of operands in expression :param new_ops: New operator to be ed to the standard operator set i.e. {'*', '/', '//', '', '+', '-') :return tuple: the expression as a string and it's solution as a float def check_user_answer (expr, ans) -> float | str: """Get user answer from stdin for given expression. Print result of comparison to actual value of expression if user answer is equal, different or an invalid number print results accordingly and return user answer :param expr: the expression to be printed :param ans: actual value expression evaluates to :return : user answer must be float or string in the case of Invalid input

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Complete the function definitions and main sections in the given template script:

from random import randint, choice
import time
import help


instructions = """ARITHMETIC PLEASE
You love number crunching don't you? Nice! so do we.
Let's crunch some numbers then:
   First you select a level (i.e. number of operands in the expression)
   then we give you an arithmetic expression to solve based on your level
\nENJOY!!!\n"""

user_data = ['\t\tSession Results:\n']


def get_level() -> int:
    """Get player level as input from stdin
    :raises ValueError
    :return n: user input value
    """


def generate_expr(n=2, *new_ops) -> tuple[str, float]:
    """Generates random arithmetic expression  n number of operands
    :param n: Number of operands in expression
    :param new_ops: New operator to be added to the standard operator set
                    i.e. {'*', '/', '//', '%', '+', '-'}
    :return tuple: the expression as a string and it's solution as a float
    """

 

def check_user_answer(expr, ans) -> float | str:
    """Get user answer from stdin for given expression.
    Print result of comparison to actual value of expression
    if user answer is equal, different or an invalid number
    print results accordingly and return user answer
    :param expr: the expression to be printed
    :param ans: actual value expression evaluates to
    :return : user answer must be float or string in the case of Invalid input
    """


def end_session(session, expr, ans, user_ans, file='ARITHP.txt') -> bool:
    """Stores the session information and requests user input to
    exit or continue the program.
    Writes the stored data to a file (default name ARITHP.txt) if the user
    wants to quit and returns True. Else returns False
    :param session: integer referencing a count of sessions run
    :param expr: expr solved in the session
    :param ans: the value the expression evaluates to
    :param user_ans: the user's answer for the expression
    :param file: name of file to write data to
    :return: True if the user wants to quit False otherwise
    """


if __name__ == '__main__':
    ...

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def end_session (session, expr, ans, user_ans, file='ARITHP.txt') -> bool:
"""Stores the session information and requests user input to
A
exit or continue the program.
Writes the stored data to a file (default name ARITHP.txt) if the user
wants to quit and returns True. Else returns False
:param session: integer referencing a count of sessions run
:param expr: expr solved in the session.
if
:param ans: the value the expression evaluates to
:param user_ans: the user's answer for the expression
:param file: name of file to write data to
:return: True if the user wants to quit False otherwise
11 11 11
name
...
== '__main____':
Transcribed Image Text:42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 def end_session (session, expr, ans, user_ans, file='ARITHP.txt') -> bool: """Stores the session information and requests user input to A exit or continue the program. Writes the stored data to a file (default name ARITHP.txt) if the user wants to quit and returns True. Else returns False :param session: integer referencing a count of sessions run :param expr: expr solved in the session. if :param ans: the value the expression evaluates to :param user_ans: the user's answer for the expression :param file: name of file to write data to :return: True if the user wants to quit False otherwise 11 11 11 name ... == '__main____':
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18.
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mmm
UNTO68
39
40
41
42
43
0-0
00
0-0
from random import randint, choice
import time
import help
instructions = """ARITHMETIC PLEASE
You love number crunching don't you? Nice! so do we.
Let's crunch some numbers then:
First you select a level (i.e. number of operands in the expression)
then we give you an arithmetic expression to solve based on your level
-\nENJOY!!!\n"""
user_data
=
def get_level () -> int:
www
['\t\tSession Results: \n']
"""Get player level as input from stdin
:raises ValueError
:return n: user input value
def generate_expr (n=2, *new_ops) -> tuple [str, float]:
"""Generates random arithmetic expression n number of operands
:param n: Number of operands in expression
:param new_ops: New operator to be added to the standard operator set
i.e. {¹*', '/', '//', '8', '+', ''}
:return tuple: the expression as a string and it's solution as a float
def check_user_answer (expr, ans) -> float | str:
"""Get user answer from stdin for given expression.
11 11 11
Print result of comparison to actual value of expression
if user answer is equal, different or an invalid number
print results accordingly and return user answer
:param expr: the expression to be printed
:param ans: actual value expression evaluates to
:return: user answer must be float or string in the case of Invalid input
Transcribed Image Text:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18. 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 mmm UNTO68 39 40 41 42 43 0-0 00 0-0 from random import randint, choice import time import help instructions = """ARITHMETIC PLEASE You love number crunching don't you? Nice! so do we. Let's crunch some numbers then: First you select a level (i.e. number of operands in the expression) then we give you an arithmetic expression to solve based on your level -\nENJOY!!!\n""" user_data = def get_level () -> int: www ['\t\tSession Results: \n'] """Get player level as input from stdin :raises ValueError :return n: user input value def generate_expr (n=2, *new_ops) -> tuple [str, float]: """Generates random arithmetic expression n number of operands :param n: Number of operands in expression :param new_ops: New operator to be added to the standard operator set i.e. {¹*', '/', '//', '8', '+', ''} :return tuple: the expression as a string and it's solution as a float def check_user_answer (expr, ans) -> float | str: """Get user answer from stdin for given expression. 11 11 11 Print result of comparison to actual value of expression if user answer is equal, different or an invalid number print results accordingly and return user answer :param expr: the expression to be printed :param ans: actual value expression evaluates to :return: user answer must be float or string in the case of Invalid input
Expert Solution
Step 1

Algorithm:

1. Print instructions to explain the game.

2. Initialize the session counter and user data list.

3. Begin loop for each session.

4. Get user level as input from stdin.

5. Generate random arithmetic expressions of the given level.

6. Get the user's answer for the expression.

7. Compare the user's answer to the actual value of the expression.

8. Print results based on the comparison.

9. Store session information and request user input to exit or continue.

10. If the user wants to quit, write stored data to a file and exit the loop.

11. Else, go back to step 4.

12. End.

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education