Limited Offer Get 25% off — use code BESTW25
No AI No Plagiarism On-Time Delivery Free Revisions
Claim Now

Task Write a program to print out Collatz sequence (https://en.wikipedia.org/wiki/ Collatz_conjecture) for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1.

Task

Write a program to print out Collatz sequence (https://en.wikipedia.org/wiki/ Collatz_conjecture) for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows:

  • If previous number is odd, the next number is 3 times the previous, plus 1.
  • If previous number is even, the next number is half of the previous.

According to Collatz proposition, the sequence ultimately reaches 1 no matter what the starting number is.

Your program should print out all numbers in the sequence down to 1. At the end, display number of iterations it took to arrive at 1, and average of all values in sequence. For prettier output, insert a line break after printing every five numbers, align the numbers in columns and format the average value to two decimal places.

After printing a Collatz sequence, your program should ask the user if they want to print out another sequence. The loop will continue until user decides to quit.

Review the sample run below to clearly understand all requirements.

Task 1

Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission, as long as the handwriting is clear and legible. However, it is strongly recommended to draw flowcharts using a drawing software. Here are links to some free drawing tools

  • Draw.io (https://www.draw.io/)
  • Lucidchart (https://www.lucidchart.com/pages/usecase/education) with an education account (register using your_csu_id@postoffice.csu.edu.au)
  • yEd Graph Editor (https://www.yworks.com/products/yed)
  • Pencil Project (https://pencil.evolus.vn/)

Task 2

Implement your algorithm in Python. Comment on your code as necessary to explain it clearly.

Your submission will consist of: /p>

  • Your algorithm through flowchart/s
  • Source code for your Python implementation
Plagiarism Free Assignment Help

Expert Help With This Assignment — On Your Terms

Native UK, USA & Australia writers Deadline from 3 hours 100% Plagiarism-Free — Turnitin included Unlimited free revisions Free to submit — compare quotes
Scroll to Top