Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please do this assignment in python. Thanks NOTE: You must work alone on this assignment; neither offer nor accept any additional help, except

Can you please do this assignment in python.
Thanks image text in transcribed
image text in transcribed
NOTE: You must work alone on this assignment; neither offer nor accept any additional help, except on a one-to-one basis with the instructor OBJECTIVE: This is a relatively easy assignment that reviews stuff you've already learned without introducing new material. You also need to honestly assess your personal understanding of looping and value-returning functions. BACKGROUND: Let's consider three rules: 1. If a number is even, divide it by 2 2. If a number is odd, triple it and then add 1 3. Stop if you ever get to 1 For example, starting with 7 7 22 11 34 1752 26 13 40 20 10 5 16 8 421 or, starting with 12: 12 6 3 10 5 16 8 4 2 1 It has been conjectured (1 suppose by someone named Ulam) that no matter what positive number we begin with, the pattern will always reach 1. This has been tested on trillions of numbers, and it has always worked, but no one has been able to prove that it works for all numbers. TASK: Write a Python program that given some number determines how many numbers are in the sequence, or stated another way, determines how many "steps (plus one) it took to get to one. For example, if given the number 12 (that is, reads a "12" from standard input), the program should determine that there are 10 numbers in the sequence (see second example above) and should print that result. Similarly, if given the number 7, the program should print that the sequence length is 17. The program should then read another number and repeat this process until a sentinel value of zero is detected. IMPLEMENTATION NOTES: Define an integer value-returning function, named ulam_sequence lengthO", that when invoked with a single (positive) integer argument returns the Ulam sequence length of that integer. For example, number 7 xulam_sequence length (number) will assign a value of 17 tox. Do not use any global variables. Read your data from standard input (stdin) using the inputO function. Don't bother prompting the user for input as you will be using the UNIX input file redirection mechanism to obtain the input values from a file. Use as your source file name ulam.py". Your output should consist of two columns of (right-justified) numbers: the first column is 12 characters wide and contains the input number, the second column is 6 characters wide and contains the number's corresponding Ulam sequence length

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions