Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Read number1
  2. Read number2
  3. Read number3
  4. Initialize largest = -

Compare Module:

  1. If number1>=number2 and number1>=number3 then set largest = number1
  2. Else, if number2>=number1 and number2>=number3 then set largest = number2
  3. Else, set largest = number3

Print Module:

  1. 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:

  1. Read number1
  2. 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.
  3. number1 = int( input("Enter a number:") )
  4. Read number2
  5. number2 = int( input("Enter a number:") )
  6. Read number3
  7. number3 = int( input("Enter a number:") )
  8. Initialize largest = -
  9. We will set largest to a very small value, say, -10^10.
  10. largest = -1e10

the Compare Module:

  1. If number1>=number2 and number1>=number3 then set largest = number1
  2. if number1 >= number2 and number1 >= number3:
  3. largest = number1
  4. Else, if number2>=number1 and number2>=number3 then set largest = number2
  5. elif number2 >= number1 and number2 >= number3:
  6. largest = number2
  7. Else, set largest = number3
  8. else:
  9. 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:

  1. Print the largest number
  2. 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:

  1. First, you need to import the math library, which contains theroundingfunctions such as ceil() and floor(). You need to type:
  2. import math
  3. Set number_reports
  4. n_reps = 100
  5. Set number_extra_reports
  6. n_extra_reps = 5
  7. Set number_pages
  8. n_pages = 20
  9. Set the number of papers per box
  10. n_papers_box = 200
  11. Set number of required papers = (number of reports + number of extra reports) * number of pages per report.
  12. n_req_papers = (n_reps + n_extra_reps) * n_pages
  13. Set number of required boxes = (number of required papers / number of papers per box) rounded up to the nearest integer.
  14. n_req_boxes = math.ceil(n_req_papers / n_papers_box)
  15. Print number of required boxes.
  16. 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

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago