1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Aleks [24]
3 years ago
15

Create a function (prob3_6) that will do the following: Input a positive scalar integer x. If x is odd, multiply it by 3 and add

1. If the given x is even, divide it by 2. Repeat this rule on the new value until you get 1, if ever. Your program will output how many operations it had to perform to get to 1 and the largest number along the way.
Computers and Technology
1 answer:
aniked [119]3 years ago
5 0

Answer:

Following are the program in python language

def prob3_6(k): #function definition

  c = 0 #variable declaration

  while k != 1: #iterating the while loop

      print(k) #print k

      if k % 2 == 0:#check if condition  

          k= k // 2 #divisible by 2

      else: #else condition

          k = k * 3 + 1  

      c = c + 1

  print(k) #print k

  print c #print count

prob3_6(3)#function call

Output:

3

10

5

16

8

4

2

1

7

Explanation:

Following are the description of program

  • Create a function "prob3_6" in this function we passing an integer parameter of type "int" named "k".
  • Inside that function we declared a variable "c" of type "int" that is used for counting purpose .
  • After that we iterated the while for print the value of when it is not equal to 1 .
  • We check if condition when k gives 0 on modulus then k is divisible by 2 otherwise else block will be executed in the else part we multiply by 3 to k and add 1 to the k variable .
  • Finally print "k" and "c"

You might be interested in
Finally, Su uses the last slide of her presentation as a summary slide. She wants to make sure the text she types automatically
Alex777 [14]

Answer:

Format Shape pane

Text Options

Shrink text on overflow

Explanation:

6 0
3 years ago
Read 2 more answers
What is the term for an element on a Webpage that contains data and procedures for how that item will react when activated
dezoksy [38]

Answer:

It is an object.  And this is because an object has the data and procedures that defines how it is going to react when it is going to be activated. The data is the details about the object, and it explains what the object actually is. And the procedures are the details of the functions that the particular objects can perform. Like for a hospital, data can be mentioning list of medication services they provide, and procedure can be like registering for any medication service, the complete process.

Explanation:

The answer is self explanatory.  

6 0
2 years ago
Need help with 4.7 lesson practice
OverLord2011 [107]

Answer:

1.a

2.sorry cant read it that wekk

3.c

Explanation:

7 0
2 years ago
I need help please and thank you
Evgen [1.6K]

Answer:

Explanation: For "BEST way to handle the situation," try Option 1, because it would possibly help them or make the Technical Support Representative do less work.

For "WORST way to handle the situation," Option 4 would be the best because you're basically just hanging up on the person.

5 0
3 years ago
What is a Type 10 SD card?
Semmy [17]

Answer: Class 10 refers to the read write speed of a memory card

Explanation:

5 0
1 year ago
Other questions:
  • Describe the Say It, Cover It, Resay It method.
    14·2 answers
  • In procedural programming, where does the flow of control usually route from the main function?
    8·1 answer
  • What is the purpose of an arraignment?
    9·2 answers
  • 2 Consider the sequence of keys (5,16,22,45,2,10,18,30,50,12,1). Draw the result of inserting entries with these keys (in the gi
    13·1 answer
  • Difference between switch case and if else statement.​
    11·1 answer
  • Laxmi was not confident that she could learn to program a computer. When she found out that two girls with similar GPA’s in her
    5·1 answer
  • Which of the following is NOT one of the Big 3 Google Applications that we discussed?
    9·2 answers
  • Please describe the role of games in modern society!
    15·2 answers
  • Modern helps to convert analog signal into digital and vice verse. true of false​
    12·1 answer
  • Look for at least ten materials tools or anything you see at home (tle)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!