Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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_sequencen, 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 0, k >= 0 and j > 0. (You can assume the user will always enter numbers, without any letters/symbols, etc.) Examples (as executed in Thonny) EXAMPLE 1: >>> 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

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Describe five career management practices

Answered: 1 week ago