The first term is any positive integer. • For each term n in the sequence, the next term is computed like this: If n is

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

The first term is any positive integer. • For each term n in the sequence, the next term is computed like this: If n is

Post by answerhappygod »

The First Term Is Any Positive Integer For Each Term N In The Sequence The Next Term Is Computed Like This If N Is 1
The First Term Is Any Positive Integer For Each Term N In The Sequence The Next Term Is Computed Like This If N Is 1 (51.66 KiB) Viewed 43 times
The First Term Is Any Positive Integer For Each Term N In The Sequence The Next Term Is Computed Like This If N Is 2
The First Term Is Any Positive Integer For Each Term N In The Sequence The Next Term Is Computed Like This If N Is 2 (51.66 KiB) Viewed 43 times
The first term is any positive integer. • For each term n in the sequence, the next term is computed like this: If n is even, the next term is n/2. If n is odd, the next term is 3n + 1. Stop once the sequence reaches 1. Here are a few examples of this sequence for different values of the first term: 8, 4, 2, 1 12, 6, 3, 10, 5, 16, 8, 4, 2, 1 . 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 Note that all three of these eventually do reach 1. In fact, it is believed (but not known) that the sequence will always reach 1, regardless of the first term chosen. This is known as the Collatz conjecture. Despite its apparent simplicity, it has so far eluded all attempts at a proof. Mathematician Jeffrey Lagarias at the University of Michigan has claimed that "this is an extraordinarily difficult problem, completely out of reach of present day mathematics." We might not be able to prove the Collatz conjecture here, but we can experiment computa- tionally with it! Write a program named collatz.py that allows the user to enter any positive integer. The program should then compute and list all the terms of the sequence until it reaches 1. At the end, show how many terms it took to get to 1 (including 1 itself). Include input validation to ensure that the user's input is positive. If it's not positive, show an error message and allow the user to re-enter the input as many times as necessary. COMP 1900 - Summer 2022 1 Lab 4 Due Wed., July 6, by 2359 CDT Example program run (underlined parts indicate what the user enters) Enter starting value (must be a positive integer): 12 12 6 3 10 5 16 8 4 2 1 Number of terms: 10
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply