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
Plz I need the answer!!!:(
dimaraw [331]

Answer:

Procedural, Visual, Logic - Based

Explanation:

7 0
3 years ago
If you are creating a new document that you know will be turned into a Web page, it is a good idea to start in _____.
Lina20 [59]
I think you should start in Web layout
7 0
3 years ago
Which of the following is not a characteristic of a healthy relation?
dlinn [17]
Where is the problem at?
5 0
4 years ago
Which of the following does Moore's law predict?
Korolek [52]

Answer:

Hi!

The correct answer is the a.

Explanation:

The Moore's law is an a empirical law that Gordon Moore predicted doing some observations about how the density of the transistors on a integrated circuit was increasing over time.

For example, this law state that if you have an integrated circuit with: 1000 transistors in 1980 then in 1981 and six months later you will have the same integrated circuit with 2000 transistors, and so on..

  • Jan 1980: 1000 transistors.
  • Jul 1981: 2000 transistors.
  • Jan 1983: 4000 transistors.
  • Jul 1984: 8000 transistors.

And that's the reason because its cost will fall too.

7 0
3 years ago
In computers, when the print command is executed, a cable carries this signal from the computer to the printer. In comparing a c
storchak [24]

Answer:

a) axon

Explanation:

In computers, when the print command is executed, a cable carries this signal from the computer to the printer. In comparing a computer to a neuron, the cable that carries the signal between the computer and the printer would be equivalent to an axon which is used to communicate messages to external cells.

Dendrites is not relevant because it represents the termination components of axon.

8 0
3 years ago
Other questions:
  • Data bars describe a graphic element that
    7·1 answer
  • On the Internet, you can use a(n)______to look for information on any topic, such as books, movies, scholarly articles, news, an
    6·2 answers
  • What technology standard is commonly used today for hard drives?
    13·1 answer
  • Micah may be able to repeat the last few digits in a phone number even if he was not paying attention. Because this is auditory
    13·1 answer
  • How do myths impact today’s society.(A
    14·2 answers
  • List the instructions of how you would make a PBJ sandwich as a series of five (5) steps (tasks) in the first column Complete th
    14·1 answer
  • Which of the following is an automated or manual file that stores information about data elements and data characteristics such
    6·1 answer
  • This OS was created by a developer named Torvalds.
    7·1 answer
  • _ is a term used for license like those issues by creative commons license as an alternative to copyright
    8·1 answer
  • HOW TO CHANGE GRADE IN SKYWARD!!
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!