Question 4: sequence Write a function sequence that accepts an number ( int ) and that prints a sequence of numbers that starts at the given number and obeys the following rules: the number 1 is the last number in the sequence (e.g stop ) if the number if even, the next number is half of it if the number is odd, the next number is one more Specifications: use a while loop print each number in the sequence one per line

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter8: Working With Trendlines, Pivottables, Pivotcharts, And Slicers
Section: Chapter Questions
Problem 8EYK
icon
Related questions
Question

Please use Python code when answering the question:

 

Question 4: sequence

Write a function sequence that accepts an number ( int ) and that prints a sequence of numbers that starts at the given number and obeys the following rules:

  • the number 1 is the last number in the sequence (e.g stop )
  • if the number if even, the next number is half of it
  • if the number is odd, the next number is one more

Specifications:

  • use a while loop
  • print each number in the sequence one per line

(Output is shown in the picture)

>>> sequence(3)
4
1
>>> sequence(4)
4
2
1
>>> sequence(17)
17
18
10
5
6
4
1
Transcribed Image Text:>>> sequence(3) 4 1 >>> sequence(4) 4 2 1 >>> sequence(17) 17 18 10 5 6 4 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Types of Function
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
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L