Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python 3 Write a function sequence () that takes one argument: n, which is the initial value of a sequence of integers. The 3 1
python 3
Write a function sequence () that takes one argument: n, which is the initial value of a sequence of integers. The 3 1 sequence starts with an integer, in this case, n, wherein each successive integer of the sequence is calculated based on these rules: . If the current number is odd, then the next number in the sequence is three times the current number plus one If the current number is even, then the next number in the sequence is half of the current number. Note Make sure to use integer division CSE 101 Fall 2017 Lab #5 Page 1 Integers in the sequence are generated based on the two rules above until the current integer is 1 Your function should start with an empty string and append characters to it as described next. The function keeps calculating the numbers in the 3n+1 sequence, and, while there are still numbers left in the sequence (meaning that the number hasn't reached 1 yet), it keeps appending letters to the string based on these rules if the number is divisible by 2, then append A' to the string if the number is divisible by 3, then append B' to the string if the number is divisible by 5, then append C' to the string if the number is divisible by 7, then append D' to the string Note: The original number n also should contribute a letter to the string. Also, append letters to your temporary string for all conditions met above. That means, for example, if the number 6 is generated, the letters A' and B' will both be appended to the string, in that order. Apply the rules in the order given. Returning to the example for 6, your code must append the letters in the order AB, not BA' In the end, your function should return the string generated by the above-described procedure Examples: Return Value Function Call sequence (4) AA sequence (12)ABABBACCAAAA' sequence (24)ABABABBACCAAAA Let's consider the second example above for a closer look: Sequence: 12 Letter: 10 16 8 2Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started