Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage 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_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

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What are the levels of analysis and perspectives in psychologypg12

Answered: 1 week ago

Question

How to solve maths problems with examples

Answered: 1 week ago