Question
Problem 1: (20 points) You are given three numbers, and you want to find the largest out of the three numbers. Using the problem analysis
Problem 1: (20 points)
You are given three numbers, and you want to find the largest out of the three numbers. Using the problem analysis tools to analyze this problem, we end up with three modules: Read, Compare and Print. The algorithms for these modules are listed below.
Algorithms for the different Modules:
Read Module:
- Read number1
- Read number2
- Read number3
- Initialize largest = -
Compare Module:
- If number1>=number2 and number1>=number3 then set largest = number1
- Else, if number2>=number1 and number2>=number3 then set largest = number2
- Else, set largest = number3
Print Module:
- Print the largest number
We will convert each step in each algorithm into a computer instruction that is written using the Python language as follows.
- First, open IDLE. In the top menu, select File -> New
- Save the new file with any name.
- Take the code that is written in bold font under each step below and type it in the new file.DO NOTcopy and paste as this might give you some errors around the double quotations!
- Save the new file.
- Run your code by pressing F5, or by going to the top menu and selecting Run -> Run Module.
- When your program runs, it will take you to the main Python console.
- On the python console, you need to input three values for the number1, number2 and number3. Just enter one value and press enter, repeat two more times.
- The largest of the three values will be printed.
Read Module:
- Read number1
- We use the input() function to read an input from the user, and use the int() function to convert that user input into an integer.
- number1 = int( input("Enter a number:") )
- Read number2
- number2 = int( input("Enter a number:") )
- Read number3
- number3 = int( input("Enter a number:") )
- Initialize largest = -
- We will set largest to a very small value, say, -10^10.
- largest = -1e10
the Compare Module:
- If number1>=number2 and number1>=number3 then set largest = number1
- if number1 >= number2 and number1 >= number3:
- largest = number1
- Else, if number2>=number1 and number2>=number3 then set largest = number2
- elif number2 >= number1 and number2 >= number3:
- largest = number2
- Else, set largest = number3
- else:
- largest = number3
The syntax of the if-else statement in Python is as follows:
if
elif
else:
Notice the indentations of the (if, elif, else) statements! Pay attention to the tabs. The (if, elif, else) keywords should be indented so that they are right underneath one another.
Print Module:
- Print the largest number
- print(largest)
Problem 2: (20 Points)
You are assigned the task of ordering paper boxes and printing copies of the board meeting report given the number of pages in the report, the number of meeting attendees, and the number of papers per paper box. You can only order whole boxes. You need to print five extra copies.
Do the same steps as in problem 2, by typing each python instruction in a new file in IDLE, and running your code. Notice how each step in the algorithm is written in python code.
Algorithms (and python code) for the read, compute and print modules:
- First, you need to import the math library, which contains theroundingfunctions such as ceil() and floor(). You need to type:
- import math
- Set number_reports
- n_reps = 100
- Set number_extra_reports
- n_extra_reps = 5
- Set number_pages
- n_pages = 20
- Set the number of papers per box
- n_papers_box = 200
- Set number of required papers = (number of reports + number of extra reports) * number of pages per report.
- n_req_papers = (n_reps + n_extra_reps) * n_pages
- Set number of required boxes = (number of required papers / number of papers per box) rounded up to the nearest integer.
- n_req_boxes = math.ceil(n_req_papers / n_papers_box)
- Print number of required boxes.
- print("The number of required paper boxes = ", n_req_boxes)
I am unable to understand this problem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started