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
geniusboy [140]
3 years ago
6

4.2.3: Basic while loop expression. Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Fol

low each number by a space. Example output for userNum = 40: 20 10 5 2 1 Note: These activities may test code with different test values. This activity will perform four tests, with userNum = 40, then with userNum = 2, then with userNum = 0, then with userNum = -1. See "How to Use zyBooks". Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.

Computers and Technology
2 answers:
Grace [21]3 years ago
7 0

Answer:

def dividedByTwo(userNum):

   out = []

   num = userNum  

   while num > 1:

       num = num//2

       out.append(num)

   try:

       if out[-1]==1:

           print(str(userNum) + ': ' + str(out))

       else:

           print("Program end never reached.")

   except:

       print("Program end never reached.")

userNum = int(input())

dividedByTwo(userNum)

Explanation:

We created a function called dividedByTwo that receives the user input, inside the function is a while loop that just allows numbers greater than one to avoid an infinite loop, this while loop will finish when the division reaches one; finally, an if statement checks if 1 was reached, otherwise, an error message will prompt.

The output of the testing in the image down below

wlad13 [49]3 years ago
4 0

Answer:

import java.io.*;

import java.util.Scanner;

class divide {

public static void main (String[] args) {

    Scanner num=new Scanner(System.in);//scanner object.

    int userNum=num.nextInt();

    while(userNum>1)//while loop.

    {

        userNum/=2;//dividing the userNum.

        System.out.print(userNum+" ");//printing the userNum.

    }

}

}

Input:-

40

Output:-

20 10 5 2 1

Input:-

2

Output:-

1

Input:-

0

Output:-

No Output

Input:-

-1

Output:-

No Output.

Explanation:

In the program While loop is used.In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.The inputs and corresponding outputs are written in the answer.

You might be interested in
What is the origin of the name “breadboard”?
8090 [49]

Answer:

Originally the word referred to a literal bread board, a polished piece of wood used for slicing bread. In the 1970s the solderless breadboard ( a.k.a. plugboard, a terminal array board) became available and nowadays the term "breadboard" is commonly used to refer to these.

7 0
4 years ago
URGENT HELP PLEASE
zysi [14]

Answer:

sorry i thought i knew it sorry

Explanation:

3 0
3 years ago
The use of multiple _______ is sometimes called using a search phrase.
zysi [14]
Hello, thank you for your question.

The answer to your question, "<span>The use of multiple _______ is sometimes called using a search phrase.," would be:

Keywords</span>
4 0
3 years ago
A piano manufacturer employs piano technicians who inspect instruments before they are shipped to customers: a.When inspecting a
77julia77 [94]

Answer:

a.When inspecting an instrument, Technicians apply specific Inspection Tests; more than one Test can be applied for an inspection. Each piano is inspected by at least one technician, and a technician can inspect more than one instrument.

Explanation:

An Inspection test  is a formal approach used to test a system or product such as machines, package, software. This can be done by dimension inspection,  visual inspection, welding inspection, function test, factory acceptance test. Three major factors to be considered in the test plan include:

Test Coverage,

Test Methods, and

Test Responsibilities

There are specific inspection tests that should be applied when inspecting an instrument. A technician can apply more than one test type to assess the authenticity of a product. More than one technician is needed to ascertain the working mehanism of a machine to ensure it has no fault. A technician  can inspect more than one instrument depending on his diversity of specialization.

5 0
3 years ago
Software that functions as an electronic version of a filing cabinet?
Dennis_Churaev [7]

Answer: There are a lot of choices

Explanation: do you want a database? You can obtain a terabyte or even larger size thumb drive or USB drive

Do want a print server? a networked drive specific for your data and if you have  to   print out anything

Do you want a connected drive to send all your documents to with organized folders?  any size drive will work for this they come all prices

Enter the electronic filing system, sometimes called document management software. These computerized filing systems provide electronic file management. In other words, they give us a simple way to store, organize, and retrieve digital files and digital documents and pdfs.

https://www.filecenter.com/info-electronic-filing-system.html here is some good software

5 0
2 years ago
Other questions:
  • How many types of string types does python support?​
    13·1 answer
  • is the process of creating a message to be communicated. a. Encoding b. Decoding c. Receiving d. Sending
    10·2 answers
  • Which line of code will print I can code on the screen?
    13·1 answer
  • What can Strings store
    15·2 answers
  • Create a class called Hangman. In this class, Create the following private variables: char word[40], progress[40], int word_leng
    11·1 answer
  • What is a written or electronic document that outlines etiquette policies for using networks and network resources?
    8·1 answer
  • How long are most personal vision statements?
    13·1 answer
  • PLEASE HELP ME WITH THIS QUESTION:
    8·1 answer
  • Who is he can anyone help me​
    14·2 answers
  • I have no idea how to use the sep and end in Python can someone help me I have a test tomorrow
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!