Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THREE QUESTIONS - USE PYTHON LANGUAGE 8. Use the Design Recipe to define a function called s umPerfectSquare that accepts a variable num and returns

THREE QUESTIONS - USE PYTHON LANGUAGE

8. Use the Design Recipe to define a function called sumPerfectSquare that accepts a variable num and returns the sum of the perfect squares less than or equal to num.

Hint: Use a while loop which and an accumulator variable.

For example, if num is 10, then the function should return 14

Since the perfect squares that are less than or equal to 10 are: 1 4 9

1 + 4 + 9 = 14

9. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation:

Fn = Fn-1 + Fn-2

F1 = 1

F0 = 1

The first 12 Fibonacci numbers follow:

1 , 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144.

Use the Design Recipe to write a function called fib which consumes n and returns the nth Fibonacci number. Use accumulation variables to implement your fib function. Hint: you will need three accumulation variables to keep track of Fn and Fn-1 and Fn-2.

You should create special cases for n of 0 or 1 and then use a for loop over the range 2 through n to compute the nth term.

For example:

Test Result
print(fib(10)) 89

10. Given the following code:

def test(number, boolean): if number >= 90 and boolean: return "Tic" elif number >= 20: return "Tac" else: return "Toe" 

Write code that prints the result of calling the test function with each of the interesting 6 combinations of cases. Your code should end up printing:

Tic Tac Tac Tac Toe Toe 

Note: you should have exactly 6 lines of code in your submission, each one of the form

print(test(___, ___)) 

with values in the blanks.

The quiz server will match your output to the above AND print out of how many of the 6 interesting cases your tests covered.

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

Big Data In Just 7 Chapters

Authors: Prof Marcus Vinicius Pinto

1st Edition

B09NZ7ZX72, 979-8787954036

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago