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]
2 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]2 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]2 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
Write a short reflection piece (it may consist of three bulleted items, with one explanatory sentence) on three things you learn
nydimaria [60]

Answers

  • OS(The Operating System) sends <em>interrupts to the processor</em> to stop whatever is being processing at that moment and computer architecture send <em>data bus</em>. This bus sends<u> data between the processor,the memory and the input/output unit.</u>
  • The operating system is a low-level software that supports a <em>computer’s basic functions</em>, such as <u>scheduling tasks and controlling peripherals</u> while the computer architecture has the <em>address bus bar</em>. This bus carries <u>signals related to addresses between the processor and the memory. </u>
  • The interface between <em>a computer’s hardware and its software</em> is its Architecture while An operating system (OS) is<u> system software that manages computer hardware and software resources and provides common services for computer programs.</u>

Explanation:

In short explanation,the Computer Architecture specifically <em>deals with whatever that's going on in the hardware part of the computer system </em>while the Operating System is the computer program <em>which has been program to execute at some instances depending on the programming instructions embedded in it</em>. An example is the MS Office.

5 0
2 years ago
What is the imitation of representing numbers with fixed point representation?
Tanzania [10]

Answer:

Hello your question is not complete, The complete question is ; <em>what is the Limitation of representing numbers with fixed point representation</em>

answer:  Limited range of values that can be represented

Explanation:

The limitation of representing numbers with fixed point representation is that there is a Limited range of values that can be represented using this method of representation

Fixed point  representation is a type of representation whereby there is a  fixed number of bits for both integer parts and fractional part.

4 0
2 years ago
Corona and app inventor can be used to develop ________.
Sidana [21]
<span>Corona and app inventor can be used to develop apps for smartphones. Corona can be used to build both games and apps from major platforms like iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. App Inventor was originally provided by Google and is now maintained by MIT.</span>
3 0
3 years ago
Zola is very skilled with Microsoft and Apple, and she knows different methods of programming. This knowledge will help make Zol
hammer [34]
I believe programmer would be your answer! If there is a multiple choice, please tell me in the comments of this answer!
3 0
3 years ago
Read 2 more answers
Which nation has a command economy
Over [174]

Answer:command economy is a key feature of any communist society. Cuba, North Korea, and the former Soviet Union are examples of countries that have command economies, while China maintained a command economy for decades before transitioning to a mixed economy that features both communistic and capitalistic elements

5 0
3 years ago
Read 2 more answers
Other questions:
  • Adam would like to reduce the size of an image that he inserted into a document. He selects the image and chooses the Crop optio
    11·2 answers
  • Match each vocabulary word to its definition.
    14·1 answer
  • For an machine using 2-dimensional even parity for error detection/correction, and the following received bytes, where is the er
    9·1 answer
  • When was kale discovered?
    9·1 answer
  • Which feature of dart helps in making the code readable,maintainable and finds type error during compile time
    15·1 answer
  • Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
    10·1 answer
  • What do u think a creative app must have? <br><br> Please answer the question ASAP!!
    5·1 answer
  • Bonjour ma question est: expliquer comment fonctionne une calculatrice qui ne contient pas une pile. Pouvez-vous m'aider?
    12·1 answer
  • Write a program with a "function" named "getMinFromInput()" that reads a list of integers from the keyboard and returns the smal
    5·1 answer
  • We love silky. she is very honest join this by using conjunction ​
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!