The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 5 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
(python 3)
Read the instructions below carefully. The instructions must be followed. This assignment is worth 5% of your grade. The assignment is due on Monday 17th of October at 8AM. No late assignments will be accepted.
The goal of this assignment is to learn and practice (via programming and quizzes) the concepts that we have learned in the last two weeks: function design, function calls, branching (that is, if statements), strings, for-loops, range function and lists.
Some of these concepts (range function and lists) will be covered more on Monday/Wednesday class (3/5 Oct). But you can certainly already work on many of the questions.
This assignment has two parts. Each part explains what needs to be
submitted. Put all those required documents into a folder called a2_xxxxxx, zip it and submit it as explained in lab 1. (In particular, the folder should have the following files:
a2_part1_xxxxxx.py,
a2_part2_xxxxxx.py and a2_part2_xxxxxx.txt
For each function that you design for this assignment you have to include docstrings that specify:
- type contract
- description about what the function does (while mentioning parameter names)
- preconditions, if any
If you do not know what this means revisit the lectures/labs from the past, or read section 3.6 from the “Practical Programming” textbook or alternatively view the following short video:
https://www.youtube.com/watch?v=Q5GR138-Mmk&index=12&list=PLkHsKoi6eZnwpn7P5G8gEBebAY8Jbky4N
*****************************************
PART 1 (20 points)
*****************************************
Suppose you are asked to design a software tool that helps an
elementary school student learn arithmetic operations. The software
allows the student to select the arithmetic operation she or he wishes
to study. The student chooses from a menu one of two arithmetic
operations: Addition and Multiplication. Then the student is asked how
many questions would he/she like to be tested on. That number is
stored in variable called n. Based on the student's
choice and answer, the software tests the student with exactly n
questions. If n is zero no test should be performed). For each of
the n questions, two random positive one-digit integers are generated; then the student is asked to enter the answer for the arithmetic operation applied to the two numbers.
At the end, the software displays a message “Well done! Congratulations.” if at least 80% of
the questions are answered correctly; if at least 60% but less than 80% of
the questions is answered correctly, the program should display
"Not too bad but please study and practice some more.", otherwise, the program should
display "Please study more and ask your teacher for help.".
a) Implement a Python function, called, perform_test, that will
execute all the arithmetic tests for a student for multiplication or
addition operations. The function has two input parameters; the first one is
an integer, 0 or 1, that represents the required operation (1 for
multiplication and 0 for addition), the second one is a positive
integer n representing the number of questions in the test. Then it gets the student to answer n questions as follows:
1. Randomly generates two positive one-digit integers.
2. Ask the student to enter the answer for the arithmetic operation of the two numbers.
3. Checks if the result is correct. If the answer is incorrect, it provides the correct answer.
As questions are answered, the correct answers are counted. The number of correct answers is returned by the function.
b) (Outside of the function) implement the main part of the program
to interact with the student to obtain the choice for either
multiplication or addition and the number of questions, then call the
function developed in part (a) to test the student (recall that the function returns the number
of correct answers). Then print one of three possible messages to the
student (“Well done! Congratulations.” or "Not too bad but please
study and practice some more." or "Please study more and ask your
teacher for help.", as determined by the criteria listed above).
Store your program in file called a2_part1_xxxxxx.py
Test it by pressing Run Module.
View the video (in the attachment) that I made called a2_part1_example_run.mp4 to see how your program
should behave when you run it.
Note that to generate a random number first import module called random
and then use the following function random.randint
Here is what help(random.randint) gives:
"randint(a, b) method of random. Random instance
Return random integer in range [a, b], including both end points."
-----------