Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Collatz sequence is generated by applying these 2 operations on the previous number. The rules are: When the current number is even, the next
The Collatz sequence is generated by applying these operations on the previous number. The rules are:
When the current number is even, the next term is half of the current term.
When the current number is odd, the next term is nthree times the current number plus
For example: generates the sequence
For this assignment, you will be writing a program that generates the Collatz sequence for a given positive integer.
First, prompt the user for a positive number greater than You can assume the user will always enter integers, but not necessarily greater than You will need to validate their input before you continue ie entering or should cause your program to tell the user that their input is invalid You should reprompt the user to enter a value if they supply bad data. Hint: use a "while" loop to keep the user "trapped" until they supply you with "good" data.
Next, your user should continually generate the next term in Collatz sequence until you reach the number The program should display whether the given number is even or odd, whether it increased from the previous number, and is it a factor of the starting number.
At the end, your program should report:
The number of steps it took to reach the number
The number of even numbers in the overall sequence including the starting number and
The number of odd numbers in the overall sequence including the starting number and
The number of increases in the overall sequence including the starting number and
The number of factors of the starting number found in the overall sequence EXCLUDING the starting number and
The average of the overall sequence including the starting number and
PLEASE DO NOT USE FOR LOOP AND def return. ONLY USE WHILE loops
Step 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