answer.
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
kolbaska11 [484]
2 years ago
9

Write an expression that continues to bid until the user enters 'n'.

Computers and Technology
1 answer:
alisha [4.7K]2 years ago
7 0

Answer:

1)

Add this while statement to the code:

while(keep_going!='n'):  

#the program keeps asking user to continue bidding until the user enter 'n' to stop.

2)

Here is the code for ACTIVITY 53.3. While loop: Insect growth:

num_insects = int(input())

while num_insects <= 100:

   print(num_insects, end=' ')

   num_insects = num_insects * 2

 

Explanation:

Here is the complete code for 1)

import random

random.seed (5)

keep_going='-'

next_bid = 0

while(keep_going!='n'):

   next_bid = next_bid + random.randint(1, 10)

   print('I\'ll bid $%d!' % (next_bid))

   print('continue bidding?', end='')

   keep_going = input()

Here the the variable keep_going is initialized to a character dash keep_going='-'

The statement keep_going = input() has an input() function which is used to take input from user and this input value entered by user is stored in keep_going variable. while(keep_going!='n'):  is a while loop that keeps iterating until keep_going is not equal to 'n'.    print('continue bidding?', end='')  statement prints the continue bidding? message on the output screen. For example the user enters 'y' when this message appears on screen. So keep_going = 'y' . So the operation in this statement next_bid = next_bid + random.randint(1, 10) is executed in which next_bid is added to some randomly generated integer within the range of 1 to 10 and print('I\'ll bid $%d!' % (next_bid))  prints the result on the screen. Then the user is prompted again to continue biffing. Lets say user enters 'n' this time. So keep_going = 'n'. Now the while loop breaks when user enters 'n' and the program ends.

2)

num_insects = int(input()) #the user is prompted to input an integer

while num_insects <= 100: #the loop keeps iterating until value of num_insects exceeds 100

   print(num_insects, end=' ') #prints the value of num_insects  

   num_insects = num_insects * 2 #the value of num_insects is doubled

For example user enters 8. So

num_insects = 8

Now the while loop checks if this value is less than or equal to 100. This is true because 8 is less than 100. So the body of while loop executes:

   print(num_insects, end=' ') statement prints the value of num_insects

So 8 is printed on the screen.

num_insects = num_insects * 2 statement doubles the value of num_insects So this becomes:

num_insects = 8 * 2

num_insects = 16

Now while loop checks if 16 is less than 100 which is again true so next 16 is printed on the output screen and doubled as:

num_insects = 16 * 2

num_insects = 32

Now while loop checks if 32 is less than 100 which is again true so next 32 is printed on the output screen and doubled as:

num_insects = 32 * 2

num_insects = 64

Now while loop checks if 64 is less than 100 which is again true so next 64 is printed on the output screen and doubled as:

num_insects = 64 * 2

num_insects = 128

Now while loop checks if 128 is less than 100 which is false so the program stops and the output is:

8 16 32 64  

The programs along with their output is attached.

You might be interested in
A city government is attempting to reduce the digital divide between groups with differing access to computing and the Internet.
sergeinik [125]

Answer:

C

Explanation:

Putting all government forms on the city web site is the least activity likely to be effective in the purpose of reducing digital divide.

Holding basic computer classes at the community centers will very much help to reduce the digital divide.

Providing free wireless internet connections at locations in low-income neighborhood will also reduce the gap of digital divide

Requiring that every city school has computers that meet a minimum hardware and software will made computing resources available to users thereby reducing digital divide.

5 0
1 year ago
(Displaying a Sentence with Its Words Reversed) Write an application that inputs a line of text, tokenizes the line with String
Serjik [45]

Answer:

I am writing a JAVA and Python program. Let me know if you want the program in some other programming language.

import java.util.Scanner; // class for taking input from user

public class Reverse{ //class to reverse a sentence

public static void main(String[] args) { //start of main() function body

Scanner input = new Scanner(System.in); //create a Scanner class object

   System.out.print("Enter a sentence: "); //prompts user to enter a sentence

   String sentence = input.nextLine(); // scans and reads input sentence

   String[] tokens = sentence.split(" "); // split the sentence into tokens using split() method and a space as delimiter

   for (int i = tokens.length - 1; i >= 0; i--) { //loop that iterates through the tokens of the sentence in reverse order

       System.out.println(tokens[i]); } } } // print the sentence tokens in reverse order

Explanation:

In JAVA program the user is asked to input a sentence. The sentence is then broken into tokens using split() method. split method returns an array of strings after splitting or breaking the sentence based on the delimiter. Here the delimiter used is space characters. So split() method splits the sentence into tokens based on the space as delimiter to separate the words in the sentence. Next the for loop is used to iterate through the tokens as following:

Suppose the input sentence is "How are you"

After split() method it becomes:

How

are

you

Next the loop has a variable i which initialized to the tokens.length-1. This loop will continue to execute till the value of i remains greater than or equals to 0.

for (int i = tokens.length - 1; i >= 0; i--)

The length of first token i.e you is 3 so the loop executes and prints the word you.

Then at next iteration the value of i is decremented by 1 and now it points at the token are and prints the word are

Next iteration the value of i is again decremented by i and it prints the word How.

This can be achieved in Python as:

def reverse(sentence):

   rev_tokens = ' '.join(reversed(sentence.split(' ')))

   return rev_tokens

   

line = input("enter a sentence: ")

print((reverse(line)))

The method reverse takes a sentence as parameter. Then rev_tokens = ' '.join(reversed(sentence.split(' ')))  statement first splits the sentence into array of words/tokens using space as a delimiter. Next reversed() method returns the reversed sentence.  Next the join() method join the reversed words of the sentence using a space separator ' '.join(). If you want to represent the reversed tokens each in a separate line then change the above statement as follows:

rev_tokens = '\n'.join(reversed(sentence.split(' ')))  

Here the join method joins the reversed words separating them with a new line.

Simply input a line of text and call this reverse() method by passing the input line to it.

4 0
1 year ago
Check your tire pressure every _____. A. month B. two months C. six months D. year
ohaa [14]

Answer: I'd say (B) Two months

Explanation: Hope its correct and helps, Good luck :)

6 0
2 years ago
Read 2 more answers
Which statement below correctly differentiates between frames and bits? Frames have more information in them than bits. Frames a
9966 [12]
<span>Frames have more information in them than bits.
</span>
<span>Frames are made up of bits but not vice versa.


A bit (BInary digiT) is the basic unit of digital. It can be 0 (logical false, off) or 1 (not logical false - true, on). Four bits are in a nybble, which can have a value of 0 - 15, eight bits are in a byte which can have a value of 0 - 255. Words vary in size, they consist of multiple bytes and are generally correlated with the system's data bus/processor data width (a 64 bit system has an 8 byte word).
</span>
5 0
2 years ago
Read 2 more answers
What does NOT match with Agile Manifesto?
Butoxors [25]

Answer:

yes

Explanation:

7 0
2 years ago
Other questions:
  • The overall purpose of CSS is to modify the way web pages look without modifying the underlying HTML code. way tables render in
    12·2 answers
  • Given: an int variable k, an int array current Members that has been declared and initialized, an int variable memberID that has
    11·1 answer
  • Brian drives a car that uses voice commands for navigation. Which field did researchers use to develop a car-based AI that under
    10·1 answer
  • A news channel runs a two-minute story on phishing scams. The report features the testimonies of a phishing victim and a compute
    7·1 answer
  • A triangular number is a number that is the sum of the integers from 1 to some integer n. Thus 1 is a triangular number because
    11·1 answer
  • 7.8.1: Function pass by reference: Transforming coordinates. Define a function CoordTransform() that transforms the function's f
    6·1 answer
  • You have been employed as a technical consultant to a computer shop chain. You are given the task of creating a short consumer b
    12·1 answer
  • #Write a function called "in_parentheses" that accepts a
    5·1 answer
  • Suppose that a class named ClassA contains a private nonstatic integer named b, a public nonstatic integer named c, and a public
    14·1 answer
  • In below freezing conditions, keep your fuel level at least _________ full to keep moisture from freezing in your gas line.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!