Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 8, Problem 4PE
Program Plan Intro
Syracuse sequence
- 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
- Check the “x%2” value is equal to 0 or not.
- 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents 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.
Chapter 8 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 8 - Prob. 1TFCh. 8 - Prob. 2TFCh. 8 - Prob. 3TFCh. 8 - Prob. 4TFCh. 8 - Prob. 5TFCh. 8 - Prob. 6TFCh. 8 - Prob. 7TFCh. 8 - Prob. 8TFCh. 8 - Prob. 9TFCh. 8 - Prob. 10TF
Ch. 8 - Prob. 1MCCh. 8 - Prob. 2MCCh. 8 - Prob. 3MCCh. 8 - Prob. 4MCCh. 8 - Prob. 5MCCh. 8 - Prob. 6MCCh. 8 - Prob. 7MCCh. 8 - Prob. 8MCCh. 8 - Prob. 9MCCh. 8 - Prob. 10MCCh. 8 - Prob. 2DCh. 8 - Prob. 3DCh. 8 - Prob. 1PECh. 8 - Prob. 2PECh. 8 - Prob. 3PECh. 8 - Prob. 4PECh. 8 - Prob. 5PECh. 8 - Prob. 6PECh. 8 - Prob. 7PECh. 8 - Prob. 8PECh. 8 - Prob. 9PECh. 8 - Prob. 10PECh. 8 - Prob. 11PECh. 8 - Prob. 12PECh. 8 - Prob. 13PE
Knowledge Booster
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
- *:To round (B) towards minus infinity the function used is roundn(A) fix(A) floor(A) ceil(A) round(A)arrow_forwardThe following function will correctly return true if its argument is an odd integer bool Isodd (int x) { return (x / 2 == 1); } True Falsearrow_forward2.a Σ : {c,A,G,T}, L = { w : w = CAG™T™C, m = j + n }. For example, CAGTTC E L; CTAGTC ¢ L because the symbols are not in the order specified by the characteristic function; CAGTT ¢ L because it does not end with c; and CAGGTTC € L because the number of T's do not equal the number of A's plus the number of G's. Prove that L¢ RLs using the RL pumping theorem.arrow_forward
- We rite a recursive function that calculates the products of natural numbers (1 through n) as follows: - asks the user to enter a positive number n - calculates and prints out the product of 1 through n (for example for n=5 the product is 120) Uploads: .c code and the outputarrow_forwardWrite a recursive function that finds factorial. Ex 4 >>>> 24 WRITE IN PYTHON PLEASEarrow_forwardc++ PLEASE TRACE THE FUNCTION Given the code:void d(int n) { if(n<2) { cout << n << " "; return; } cout << n << " "; d(n/3);} 1. Trace the function when n is 12.arrow_forward
- C program for the longest sequence of increasing numbers. Use the function: void longestSequence(int b[], int sizeB); Input: 1 3 10 1 7 8 10 30 0 Output should be: Longest sequence is 1, 7, 8, 10, 30.arrow_forwardthe minimal POS of the following function is (f (A, B,C) = []M(2,6)) : Select one: O A. A.B О в. В + С' О с. В' + С O D. A + B CamScanner+ gub da guaallarrow_forwardF(x.y,z)=x'y'z+x'yz+xy'z'+xy'z can you simplify this and draw the diagram of the simplified functionarrow_forward
- #5.Incorrect gurantee downvote. Euler's totient function, also known as phi-function ϕ(n),counts the number of integers between 1 and n inclusive,which are coprime to n.(Two numbers are coprime if their greatest common divisor (GCD) equals 1)."""def euler_totient(n): """Euler's totient function or Phi function. Time Complexity: O(sqrt(n)).""" result = n for i in range(2, int(n ** 0.5) + 1): if n % i == 0: while n % i == 0: n //= i.arrow_forward497 Bytes Write a recursive function that returns the sum of the digits of a given integer.Input format :Integer NOutput format :Sum of digits of NConstraints :0 <= N <= 10^9Sample Input 1 :12345Sample Output 1 :15Sample Input 2 :9Sample Output 2 :9 Solution:///////////// public class solution { public static int sumOfDigits(int input){ int sum; if(input<10){ return input; } sum = (input % 10) + sumOfDigits(input / 10); return sum; }}. .arrow_forwardCreate a function which counts how many lone 1's appear in a given number. Lone means the number doesn't appear twice or more in a row. Examples count LoneOnes (101) ➡2 count LoneOnes (1191) → 1 count LoneOnes (1111) count LoneOnes (462) 0arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr