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
Kevin gets a call from a user who is trying to install a new piece of software. The user doesn’t have administrative rights, so
lyudmila [28]

Answer:

use Remote Desktop

Explanation:

8 0
3 years ago
Your instructor has asked you to perform some research regarding a computer OS capability of distinguishing spoken words. What i
tekilochka [14]
It’s A !!!!!!!!! Just did it
3 0
3 years ago
Technician A says that automotive engine blocks are usually classified by the number of cylinders the block. Technician B says t
viva [34]
<span>A. Both Technicians A and B is the answer</span>
8 0
3 years ago
Personal Web Page Generator Write a program that asks the user for his or her name, then asks the user to enter a sentence that
Fudgin [204]

Answer:

see explaination

Explanation:

The following code is in python 3.5 and above:

# Create a main method

def main():

# Accept name from the user

name = input("Enter your name: ")

# Accept describe yourself from the user.

describe = input("Describe yourself: ")

# Create a file object

f = open('person.html','w')

# Creat a string to store the html script.

message = """<html>

<head>

</head>

<body>

<center>

<h1>"""+name+"""</h1>

</center>

<hr/>"""+describe+"""<hr/>

</body>

</html>"""

f.write(message)

f.close()

main()

7 0
3 years ago
Explain how data structures and algorithms are useful to the use of computer in data management<br>​
laiz [17]

Answer:

programmers who are competent  in data  structures and algorithms  can easily perform the tasks related  to data processing ,automated reasoning ,or calculations . data structure and algorithms  is significant  for developers  as it shows their problems solving abilities amongst the prospective employers .

5 0
3 years ago
Other questions:
  • you are a software engineering consultant and have been called in by the vice president of finance of a corporation that manufac
    10·1 answer
  • Describe the Say It, Cover It, Resay It method.
    14·2 answers
  • Is a software program that allows users to access the world wide web
    10·1 answer
  • what evidence supports the claims that the Taj Mahal is a symbol of historical and cultural glory as well as an architectural ma
    8·1 answer
  • How is IT related to new business initiatives?
    6·1 answer
  • When you move a paragraph in a document that includes text with a footnote, what happens to the footnote reference?
    7·2 answers
  • Who were called “freedmen” during the reconstruction period?
    15·2 answers
  • Jane is creating a slide that will have a large heading and number of bullet points below it. What slide format should she use?
    12·1 answer
  • Jabria are you smart
    14·2 answers
  • Consider the following method, which is intended to return the index of the first negative integer in a given array of integers.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!