Question: Python question using for loop Question 4 [40 points] Dr. Vink of the Math Lab has made a conjecture about a particular sequence of numbers

Python question using for loop

Python question using for loop Question 4 [40 points] Dr. Vink ofthe Math Lab has made a conjecture about a particular sequence of

Question 4 [40 points] Dr. Vink of the Math Lab has made a conjecture about a particular sequence of numbers that he calls the Vink sequence. He claims that for any odd integer k > 0, a sequence of numbers can be constructed as follows. Start with an integer n > 0. Then, the next term in the sequence is if n is even, or 3n + k if n is odd. Vink claims that this sequence will eventually produce a term of 1 after some number of terms. For example, starting with n = 9 and k = 1, we get the sequence 9, 28, 14, 7, 22, 11, 34, 17,52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, which reaches 1 after 20 terms. To help check Vink's claim, we will write code that checks how many terms it takes to converge to 1 with given values of n and k. You must write a function vink_sequence(n, k, j) that computes the first j terms of the Vink sequence for the given values of n and k. If none of the j terms are 1, then the function should return -1. If you do encounter a term of 1, then the function should stop computing terms and immediately return the number of terms that have been computed so far. For example, if the 37th term of the sequence is 1, then the function should immediately return the value 37. Next, outside your function, ask the user to type in a value for n, k and j. If either n >> %Run vink.py Enter n: 27 Enter k: 1 Enter j: 1000 112 EXAMPLE 2: >>> %Run vink.py Enter n: 9 Enter k: 2 Enter j: 5 -1 EXAMPLE 3: >>> %Run vink.py Enter n: 5 Enter k: -2 Enter j: 100 Invalid input. EXAMPLE 4: >>> %Run vink.py Enter n: 0 Enter k: 5 Enter j: 10 Invalid input

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!