Your program shall generate a random arithmetic expression based on a user's level (this should range from 2-5). Use the level number to determine the number of operands in the expression ex. level 2 generates expression of the form 2-5 The program shall display the generated expression and collect user input for an answer to the expression. The program shall compare the user's given answer to the program evaluated result (round to 2dp), and print the outcome: ie. invalid input, wrong answer (different from computed value) or right answer (equal to computed value within 2dp) Your program shall allow user to repeat this process in one run of the application (keep track of number of sessions for each run)

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 13E
icon
Related questions
Question

please do it in python language

 

first picture is problem and second one is just hint for you.

 

thanks

 

Your program shall generate a random arithmetic expression based on a user's level (this should range from 2-5).
Use the level number to determine the number of operands in the expression ex. level 2 generates expression of the form 2-5
The program shall display the generated expression and collect user input for an answer to the expression.
The program shall compare the user's given answer to the program evaluated result (round to 2dp), and print the outcome: ie. invalid input, wrong answer (different from
computed value) or right answer (equal to computed value within 2dp)
Your program shall allow a user to repeat this process in one run of the application (keep track of number of sessions for each run)
Transcribed Image Text:Your program shall generate a random arithmetic expression based on a user's level (this should range from 2-5). Use the level number to determine the number of operands in the expression ex. level 2 generates expression of the form 2-5 The program shall display the generated expression and collect user input for an answer to the expression. The program shall compare the user's given answer to the program evaluated result (round to 2dp), and print the outcome: ie. invalid input, wrong answer (different from computed value) or right answer (equal to computed value within 2dp) Your program shall allow a user to repeat this process in one run of the application (keep track of number of sessions for each run)
default
f"""Roots of a Quadratic function
Given a quadratic function:
f(x) = ax{chr(exb2)} + bx + C
This program takes as user input real number values for: a b c
and calculates the values of x for which f(x) = 0 using the formula:
(-b {chr(0x00b1)} {chr(0x221a)} (b{chr(exb2)} - 4ac))/2a
"".splitlines ()
11111
=
def print_about (about: list
default, char-'*'):
Prints a fancy program title and user instructions
:param about Information to be printed
:param char- A character to embellish the output
***
I
# find Length of the Longest Line in about and add 10 for extra padding
length = max([len (line) for line in about]) + 10
print (char*length) # 1st Line with only symbol char
print (f"{char}{' * (length - 2)}{char}") # 2nd Line: space bordered by symbol char
# print title i.e. first Line, upper case and centered bordered by symbol char
print (f'{char}{about [0]. upper():^{length-2}}{char}')
=
# print 'About' padded with 3 spaces and left aligned
print (f"{char}\t{'About:':<{length-4}}{char}" .expandtabs (3))
# Print instructions i.e. items 1-Last in about
# Each instruction is padded with 3 spaces and Left aligned
for i in range(1, len(about)):
print (f' {char}\t\t{about [i]:<{length-7}}{char}' .expandtabs (3))
# closing Lines must mirror open Lines
print (f"{char}{'* (length - 2)}{char}")
print(char* length)
print () # add trailing blank Line
if_name_
==
'__main__':
print_about()
Transcribed Image Text:default f"""Roots of a Quadratic function Given a quadratic function: f(x) = ax{chr(exb2)} + bx + C This program takes as user input real number values for: a b c and calculates the values of x for which f(x) = 0 using the formula: (-b {chr(0x00b1)} {chr(0x221a)} (b{chr(exb2)} - 4ac))/2a "".splitlines () 11111 = def print_about (about: list default, char-'*'): Prints a fancy program title and user instructions :param about Information to be printed :param char- A character to embellish the output *** I # find Length of the Longest Line in about and add 10 for extra padding length = max([len (line) for line in about]) + 10 print (char*length) # 1st Line with only symbol char print (f"{char}{' * (length - 2)}{char}") # 2nd Line: space bordered by symbol char # print title i.e. first Line, upper case and centered bordered by symbol char print (f'{char}{about [0]. upper():^{length-2}}{char}') = # print 'About' padded with 3 spaces and left aligned print (f"{char}\t{'About:':<{length-4}}{char}" .expandtabs (3)) # Print instructions i.e. items 1-Last in about # Each instruction is padded with 3 spaces and Left aligned for i in range(1, len(about)): print (f' {char}\t\t{about [i]:<{length-7}}{char}' .expandtabs (3)) # closing Lines must mirror open Lines print (f"{char}{'* (length - 2)}{char}") print(char* length) print () # add trailing blank Line if_name_ == '__main__': print_about()
Expert Solution
Step 1

Algorithm:

  1. Take input from the user for the level (2-5)
  2. Generate a random expression based on the level using the "generate_expression" function
  3. Display the generated expression
  4. Collect user input for an answer to the expression
  5. Evaluate the expression using the "evaluate_expression" function
  6. Compare the user's given answer with the program-evaluated result using the "check_answer" function
  7. Print the outcome: "Invalid input", "Wrong answer" or "Right answer"
  8. Repeat the process until the user chooses to exit
  9. Keep track of the number of sessions
  10. Display the total number of sessions when the user chooses to exit.
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Structure chart
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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning