Question: def seq3np1(n): Print the 3n+1 sequence from n, terminating when it reaches 1. while n != 1: print(n) if n % 2 == 0:
def seq3np1(n):
""" Print the 3n+1 sequence from n, terminating when it reaches 1."""
while n != 1:
print(n)
if n % 2 == 0: # n is even
n = n // 2
else: # n is odd
n = n * 3 + 1
print(n) # the last print is 1
seq3np1(3)
--------------------------------------------------------------------------------------------------------
code it in python

Activity 2: Repeat the call to seq3npl using a range of values, up to and including an upper bound. Now that we have a function that can return the number of iterations required to get to 1, we can use it to check a wide range of starting values. In fact, instead of just doing one value at a time, we can call the function iteratively, each time passing in a new value. Create a simple for loop using a loop variable called start that provides values from 1 up to 50. Call the seq3mpl function once for each value of start. Modify the print statement to also print the value of start. copy and paste your code here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
