Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So far you have learned how to write a program using python that: Takes input . Gives output Executes mathematical functions Handles strings Executes loops

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions