Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function juggle() that has one parameter: num. The function generates a

ID: 3931172 • Letter: W

Question

Write a function juggle() that has one parameter: num.

The function generates a sequence of numbers as follows:

It starts with num

If num is even, it replaces num with the integer value of num **0.5

If num is odd, it replaces num with the integer value of num **1.5

This repeats until it hits num == 1, printing all the values of num along the way

The function prints the numbers, each one on a line by itself, including the starting value of num and the ending value of 1. This time do it with recursion. DO NOT use any type of loop (while or for). Make sure to include a meaningful docstring. I included in documents for this assignment, a file named halves_recursive.py. Your solution will be similar except you will have two recursive steps.

Test calling function with num = 8, 17

Explanation / Answer

def juggle(n):
    if n<=1:
        return n
    else:
        if n%2==0:
            n=int(n**0.5)
            print n
            juggle(n)
        else:
            n=int(n**1.5)
            print n
            juggle(n)
num= input("Enter a number:")
print num
juggle(num)

Output:

Test Case1:

Enter a number: 8
8
2
1

Test Case2:

Enter a number:17
17
70
8
2
1

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote