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
Write a class named Taxicab that has three **private** data members: one that holds the current x-coordinate, one that holds the
Licemer1 [7]

Answer:

See explaination

Explanation:

class Taxicab():

def __init__(self, x, y):

self.x_coordinate = x

self.y_coordinate = y

self.odometer = 0

def get_x_coord(self):

return self.x_coordinate

def get_y_coord(self):

return self.y_coordinate

def get_odometer(self):

return self.odometer

def move_x(self, distance):

self.x_coordinate += distance

# add the absolute distance to odometer

self.odometer += abs(distance)

def move_y(self, distance):

self.y_coordinate += distance

# add the absolute distance to odometer

self.odometer += abs(distance)

cab = Taxicab(5,-8)

cab.move_x(3)

cab.move_y(-4)

cab.move_x(-1)

print(cab.odometer) # will print 8 3+4+1 = 8

7 0
2 years ago
The postorder and preorder traversal of a binary tree are given below - postorder : D E B F G C A preorder : A B D E C F G respe
jeka57 [31]

Answer: The answer is A

Explanation:

in  the attachment

6 0
3 years ago
How is AI used in racing ?
NikAS [45]
This now allows human pilots to race together with AI drivers. The AI driver is, in this case, the intelligent software that gathers all data from the sensors and other touchpoints to drive the car.
3 0
2 years ago
Identifica una necesidad que implique la reducción de los efectos perjudiciales relacionados al uso de los recursos energéticos.
ELEN [110]

Answer:

Baje las persianas o cierre las cortinas en los días calurosos, para mantener la casa fresca y reducir el uso de ventiladores eléctricos o aire acondicionado. Deje que la ropa se seque naturalmente. Mantenga las tapas en las ollas cuando cocine para ahorrar energía. Use baterias recargables.

5 0
2 years ago
Which of these is not a sub-claim "Our Clean Power Plan" uses to support its main claim? The CPP protects public health. The CPP
Leno4ka [110]
The CPP cleans the air statement is not a sub-claim of Our Clean Power Plan.

It is the efforts of President Barrack Obama and the U.S. Environmental Protection Agency that has the main goal of lessening to cutting carbon pollution from the present power plants
4 0
3 years ago
Read 2 more answers
Other questions:
  • The piston engine uses the ________ to convert the reciprocating motion of the piston into rotary motion.
    13·1 answer
  • ____ data exist in a format that does not lend itself to processing that yields information.
    8·1 answer
  • 1. Which of the following options will allow you to insert a quick table? (1 point) Insert ribbon > Shapes drop-down menu
    6·2 answers
  • The use of IDPS sensors and analysis systems can be quite complex. One very common approach is to use an open source software pr
    9·2 answers
  • Interruption attacks are also called ___ attacks:
    8·1 answer
  • What is the name of the function below?<br><br> function go(){<br> alert("hello everybody");<br> }
    10·1 answer
  • What does PR stand for ?
    15·1 answer
  • Use the ________ tag to configure a generic area on a web page that is embedded within a paragraph or other block display elemen
    12·1 answer
  • The courts can adjust the penalties in lawsuits to reflect the fact that infringements may be _____.
    5·2 answers
  • Instructions
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!