Question: CODE= PYTHON!!! Programming Assignment 2 So far you have learned how to write a program using python that: Takes input Gives output Executes mathematical functions

CODE= PYTHON!!!  CODE= PYTHON!!! Programming Assignment 2 So far you have learned how

Programming Assignment 2 So far you have learned how to write a program using python that: Takes input Gives output Executes mathematical functions Handles strings Executes loops Exits loops early For this programming assignment, you will be writing a program that can execute the functions described by the Collatz conjecture. This conjecture is famous in mathematics, is yet to have a proof discovered, and is considered among the hardest mathematical conjectures to resolves. Fortunately, you are not being asked to resolve the conjecture. You are only being asked to write a program that executes the functions and outputs the number of steps it took. The two functions of the Collatz conjecture are stated as follows: Given any positive whole number, you can reduce it to 1 by following the following rules: 1. If the number is odd, then multiply it by 3 and add 1 (3n+1) 2. If the number is even, then divide it by 2 (n/2) The conjecture states that following these rules, any positive whole number you start with will eventually reach 1 (that is, there are a finite number of solving steps). I want you to write a program that takes a number as input and outputs the number of solving steps it took to reach 1. A solving step is counted for each time you have to follow either rule 1 or rule 2. Let's take a look at an example: Given the starting number of 5 Step 1 (rule 1) gives 16 Step 2 (rule 2) gives 8 Step 3 (rule 2) gives 4 Step 4 (rule 2) gives 2 Step 5 (rule 2) gives 1 It took 5 steps (1 for rule 1, and 4 for rule 2). For this assignment, you will need to provide a written description of your approach as well as the python code you have come up with to put your approach into action. Hints I will give: the modulo operator is helpful while loops are helpful At a minimum you need to accept a numerical input and output the number of steps required to reach 1 by following the rules of the Collatz conjecture. Be sure to describe your approach and each step in your code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!