Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Concept explainers

Question
Book Icon
Chapter 8, Problem 4PE
Program Plan Intro

Syracuse sequence

Program Plan:

  • Declare the “syr” function.
    • Check the “x%2” value is equal to 0 or not.
      • Calculate the “syrX” value.
    • Check the “x%2” value is equal to1 or not.
      • Calculate the “syrX” value.
    • Return the value to the main function
  • Declare a main function. Inside the main function,
    • Get the input number from the user.
    • Check “x” is greater than 1 or not.
      • Call the “syr” function with the input value.
      • Set the value.
      • Display the Syracuse sequence.
  • Call the main function.

Blurred answer
Students have asked these similar questions
Computer Science This is an introductory exercise to the manipulation of random variables with Python as a language for scientific computing and numerical computation. You have: f(x) = Ae-0.1x)° 4 x*, 0
Q11/ A function f(t) is said to be even if: Oa) f(t) = f(-t) Ob) f(t) = -f(-t) Oc) f(t) # f(-t) %3D Od) None of these
Programming Language :- C 7. A function is defined for a positive integer n as follows: 3n + 1, if n is odd f(n) = { n if n is even 2 We consider the repeated application of the function starting with a given integer n, as follows: f(n), f(f(n)), f(f(f(n))), It is conjectured that no matter which positive integer n you start from; this sequence eventually will reach to 1. If n = 13, the sequence will be 13, 40, 20, 10, 5, 16, 8, 4, 2, 1. Thus if you start from n = 13, you need to apply function 10 times to reach 1. Write a recursive function that takes n as an input number and returns how many times function f has to be applied repeatedly to reach 1.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr