[Solved]Create New Python File Sequencegenpy Write Function Sequence Takes One Parameter N Initial Q37243809
Create a new Python file sequencegen.py and write the functionsequence that takes one parameter: n, which is the initial value ofa sequence of integers. The 3n + 1 sequence starts with an integer,n in this case, wherein each successive integer of the sequence iscalculated based on these rules: 1. If the current value of n isodd, then the next number in the sequence is three times thecurrent number plus one. Note: Make sure to use integer division.2. If the current value of n is even, then the next number in thesequence is half of the current number. 3. Integers in the sequenceare generated based the two rules above until the current numberbecomes 1. Your function should start with an empty string andappend characters to it as described next. The function keepscalculating the numbers in the 3n + 1 sequence, and while there arestill numbers left in the sequence (meaning that the number has notreached 1 yet), it keeps appending letters to the string based onthese rules: 1. If the number is divisible by 2, then append ‘A’ tothe string. 2. If the number is divisible by 3, then append ‘B’ tothe string. 3. If the number is divisible by 5, then append ‘C’ tothe string. 4. If the number is divisible by 7, then append ‘D’ tothe string. Note: The original number n also should contribute aletter (or letters) to the string. Also, append letters to youraccumulating string for all conditions met above. That means, forexample, if the current number is 6, the letters ‘A’ and ‘B’ willboth be appended to the string, in that order. Apply the rules inthe order given. Returning to the example for 6, your code mustappend the letters in the order ‘AB’, not ‘BA’. Note: If you findany helper functions useful, feel free to use them. In fact, Isuggest that you try to define and use helper functions. This ideaapplies not only to this problem, but to any problem. In the end,your function should return the string generated (accumulated) bythe procedure described above. If n initially is less than 1, thefunction returns an empty string. Example calls: sequence(4)returns ‘AA’ sequence(12) returns ‘ABABBACCAAAA’ sequence(24)returns ‘ABABABBACCAAAA’ Let’s consider the second example abovefor a closer look: Sequence:| 12 | 6 | 3 | 10 | 5 | 16 | 8 | 4 | 2———-+—-+—-+—-+—-+—-+—-+—-+—-+—- Letters: |AB | AB | B | AC | C | A | A | A | A
Expert Answer
Answer to Create a new Python file sequencegen.py and write the function sequence that takes one parameter: n, which is the initia… . . .
OR

