Graded Problem Set #3.1
Loop Problems
Background
These problems should be completed on your own. Unlike the practice problems, where you are allowed, and even encouraged, to talk about the process with your classmates, these should be attempted on your own. If you have difficulty with these, please reach out to me for assistance or guidance.
These problems will be completed using an editor such as Thonny or IDLE and submitted to Autolab for grading.
Activities
Please try to make your program output look as much like the example as possible and verify it works with the example input provided. If you have difficulty finding the information or understanding how to approach the problem, you should contact me.
To complete this activity, you will need to create the following scripts:
- LOOP G1 - pyramid()
- LOOP G2 - gcd()
LOOP G1
It's a Giant Pyramid Scheme
Ahhotep was an ancient Egyptian queen who lived from approximately 1560-1530 BC (Only 30 years old and still the queen. And what are you doing with your life?)
She has come back to life ala Night at the Museum and wants to build a pyramid to go along with the other pyramids built by her ancestors. She wants to calculate how many blocks of stone it will require.
- We will assume that a pyramid is solid (it will not be used as a tomb).
- The top layer would have 12 or 1 stone block
- The next layer down would have 22 or 4 stone blocks
- The next layer down would have 32 or 9 stone blocks
- The next layer down would have 42 or 16 stone blocks
- Thus, a 2 layer pyramid would require 5 stones (1+4)
- while a 4 layer pyramid would require 30 stones (1+4+9+16)
Write a Python function that conforms to the following:
- Function name
- pyramid()
- Parameters
- a non-negative integer
- Return value
- The number of bricks required to make the pyramid given the description above
- Examples
LOOP G2
Well we have THAT in common!
- Ms. Aljehbrah is a math teacher.
- She is having a problem teaching her students about the Greatest Common Divisor.
- If you recall, the GCD is the largest integer that is a divisor for two (or more) integers.
- For example,
- the GCD of 24 and 54 is 6 since no number larger than 6 divides evenly into both 24 and 54.
- the GCD of 24 and 8 is 8 since 8 divides 24 on its own.
- the GCD of 9 and 8 is 1 since neither number has any factor in common.
- In Middle/High School math we often teach students a variety of algorithms that determine the GCD of two number.
- One algorithm for calculating GCD is the following:
get two integers labled m and n set d to be the smaller of m and n while m is not divisble by d OR n is not divisible by d subtract one from d report d as the greatest common divisor
- One algorithm for calculating GCD is the following:
Write a Python function that conforms to the following:
- Function name
- gcd()
- Parameters
- An integer
- A second integer
- Return value
- The GCD as calculated by the technique above=
- Examples