Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python, i think we have to classify using list = [] The purpose of this lab is to give you practice with repetition using

in python, i think we have to classify using list = [] image text in transcribed
image text in transcribed
The purpose of this lab is to give you practice with repetition using while loops, using conditional statements, and handling exceptions. Program Description Consider this rule for transforming a positive integer n : if n is even, divide it by 2 if not, multiply it by 3 and add 1 The Collatz conjecture says that, no matter what integer you start with, applying this transformation over and over will eventually reach the value 1. Write a program that prompts the user for a starting value n, and then applies the above transformation repeatedly until n is 1 . You must use an exception handler to catch all invalid input that are not integers. In addition, you must validate your input to make sure it's a positive number. Once you have valid input, the program should count the number of transformations it took to reach 1 and print that count and the transformations. The program should stop after one positive number is computed for generating its Collatz conjecture and stop. If the input value is invalid, the user must be prompted repeatedly until one valid value is supplied. Comments: For this lab, you must include your name in a comment, and also include comments denoting where input is collected, where exceptions are handled, and where the Collatz calculations are performed. Example Output: Sample output 1: Enter a positive number: 11 11>34>17>5226>13>4020>10>5>16>8>4>21 14 transformations Sample output 2 : Page 1 of 2 Enter a positive number: Please enter an integer value greater than zero

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

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

In what way is a celebrity or politician a brand?

Answered: 1 week ago