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
Which of the following is a group of email names and addresses used for mass distribution of a message?
Jet001 [13]

Answer:

Option D is the correct answer for the above question.

Explanation:

Email list (as the name suggests) is defined as the set of an Email address. It is also the group of address which is needs for message distribution because an Email address is the only necessary part to send the mail which is also called the message. When a user wants to send the mass Email or message then he needs a list of email which can be filled at the "TO" or "CC" or "BCC" part of the compose mail and it can be able to send the mass message.

The above question asked about the list which is useful for the mass message then the answer is an Email list which is stated from the option D. Hence option D is the correct answer while other is not because--

  • Option A states the actor list which is not required to send the mail.
  • Option B states the client list which is not required to send the mail.
  • Option C states the chat list which is not required to send the mail.
3 0
2 years ago
These tools gather information from sources such as emails, text messages, and tweets and make the information instantly and pub
babunello [35]

Answer:

Crisis-Mapping

Explanation:

Social networks are characterized by the immediacy of the content that users produce, and that same feature can be transferred to the online mapping of crises and conflicts.

Characteristics Crisis-Mapping:

  • Real-time information processing.
  • Immediacy;
  • Visualization of the aggregated information can allow the detection of patterns that cause new analyzes to be undertaken or work hypothesis to verify.
  • Continuity in the tasks, the maps record activity without interruption during the twenty-four hours of the day and seven days per week.
  • Flexibility in the protocols, since the tasks are distributed and evolve according to the dynamics (the crisis maps evolve with the crisis itself).
8 0
3 years ago
If the motherboard is not getting power, it will not start the boot. ... A four-year old laptop will not boot and presents error
lakkis [162]

Answer:

<em>The right order of steps you should take to repare the laptop is: D A C B</em>

<em>Explanation:</em>

<em>D. Ask yourself if the laptop is still under warranty: Because they will replace the board for you or give you a new machine.</em>

<em>A. Ask yourself if replacing the motherboard will cost more than purchasing a new laptop: since technology evolve every day, you might consider buying a new faster, better, advanced machine.</em>

<em>C. Find the service manual to show you how to replace the motherboard: the support assistence will guide you trhough the right way of replacing the board.</em>

<em>B. Find a replacement motherboard: choose the specific one or maybe try to find a better model, that can improve your computer performance.</em>

7 0
3 years ago
What is the correct html element for playing video files?
Neko [114]
HTML stands for Hyper Text Markup Language. It is the most commonly language used for <span>creating web pages and web applications. </span>

<span>The correct HTML element for playing video files is <video>.
</span>

To show a video in HTML, use the <video> element:

Example:<span><video<span> width="320" height="240" controls</span>></span>
  <span><source<span> src="video 1.mp4" type="video/mp4"</span>></span>
  <span><source<span> src="movie.ogg" type="video/ogg"</span>></span>
<span></video<span>></span></span>
4 0
3 years ago
Read 2 more answers
Hey guys do you mind subscribing to my utube BrokenShoe once I hit 40 subs I'm doing a massive giveaway of gift cards ps: also g
luda_lava [24]

Answer:

ok

Explanation:

4 0
3 years ago
Other questions:
  • Assume that the 100,000 element integer array that you allocated starts at address 0x50000000 in memory, the size of an integer
    6·1 answer
  • The major difference between a calculator and a computer, when performing calculations, is that a
    10·1 answer
  • Which address correctly represents one that is composed of two halves, one assigned to a network adapter manufacturer, and the o
    6·1 answer
  • Refer to the following code segment. You may assume that array arr1 contains elements arr1[0],arr[1],...,arr[N-1], where N = arr
    8·1 answer
  • 10.7 LAB: Fat-burning heart rate Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus th
    8·1 answer
  • You manage a network that uses switches. In the lobby of your building, there are three RJ45 ports connected to a switch. You wa
    5·1 answer
  • Abby has always dreamed of having her own ice cream shop. Now as a young entrepreneur she has decided to pursue her dream, but s
    13·1 answer
  • Please help i only have 20 minuets
    5·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • To find detailed information about the origin of an email message, look at the ________________.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!