Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve this using python Arrite a funetion that will ealculate the zucker Index of fa number. The zucker Index is a thing I made up

Solve this using python image text in transcribed
Arrite a funetion that will ealculate the zucker Index of fa number. The zucker Index is a thing I made up for this fproblem, and it is defined as follows: istart with a number. If the number is even, divide it by \#-2 (negative 2). If the number is positive and odd, subtract 11. If the number is negative and odd, add 1 . *r you repeat this sequence, the number will eventually rreach 0 . For example, imagine we started with the number 19: F19 is positive and odd, so subtract one to get 18 18 is positive and even, so divide by -2 to get -9 -9 is negative and odd, so add 1 to get -8 . -8 is negative and even, so divide by -2 to get 4. 4 is positive and even, so divide by -2 to get -2 . 2 is positive and odd, so subtract 1 to get 0. *Starting with 19, this sequence converges on 2 in 7 iterations: \#19 to 18,18 to 9,9 to 8,8 to 4,4 to 2,2 to 1 , 1 to 0 \#Implement a function called zucker. zucker should take as \#input an integer, and return the integer's zucker Index; \#that is, the number of iterations it takes for the \#number to reach 0. For example, zucker (19) would return 7 \#because it took 7 iterations to converge on 0. \#Add your code herel \#Below are some lines of code that will test your function. \#You can change the value of the variable(s) to test your \#function with different inputs. \# \#If your function works correctly, this will originally \#print: 7,6 , and 19 , each on their own lines. print (zucker (19)) print (zucker (17)) print (zucker (3678))

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions