For this question task is to complete the method wonder(number)…
Question Answered step-by-step For this question task is to complete the method wonder(number)… For this question task is to complete the method wonder(number) which takes a single positive int as a parameter (you do no need to check the input, all tested inputs will be positive integers). The method should then repeatedly apply the following function: mathrm{wonder}(x) = left{begin{array}{ll}3x + 1 & text{if } x text{ is odd.}x/2 & text{if } x text{ is even.}end{array}right.wonder(x)={3x+1x/2if x is odd.if x is even. It should record the result of each step in a list. It should stop once the result value is 1. It should then return the list. The initial and final value should be in the list.For example, the input 5 should give the result [5, 16, 8, 4, 2, 1]. My code:def wonder(number): while(function != 1): if(number % 2 != 0): function = (3*number) + 1 if (number % 2 == 0): function = number/2 return [function] Computer Science Engineering & Technology Python Programming PROGRAMMIN 41039 Share QuestionEmailCopy link Comments (0)


