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
nlexa [21]
1 year ago
10

Assuming that the valid cost should be between 100 and 200, does the following code snippet test this condition correctly?

Computers and Technology
1 answer:
schepotkina [342]1 year ago
8 0

Answer:

  • No, Only the value between 100 and 200 can not test the code correctly.
  • This code snippet ensures that the cost value is between 100 and 200.

Explanation:

  • The above code has three condition test- if, else-if and else.
  • The first condition is true for the value which is a minimum of 100.
  • The else if condition is true for the value which is maximum from 200.
  • Then the else condition is used when the if and else if condition is false.
  • when the user gives the value between 100 and 200 then it will test that the value lies between 100 or 200.
  • To test the whole scenario there must be one value is less than 100 and greater than 200.
You might be interested in
You are attempting to open a file containing a list of integer numbers, each on a separate line, and read them into Python as in
baherus [9]

Answer:

The answer to this question can be given as:

Statement:

number = int(line.strip())

Explanation:

In the above statement, we declare an integer variable number accept the integer value from the file that name is line. In this line, we use the strip() function. This function returns a duplicate string with both starting and tracking characters removed (based on the string parameter passed). The strip() function removes characters from both sides (left and right) based on the parameter(a string defining the collection of characters to be removed).

7 0
1 year ago
Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", a
Nikolay [14]

Answer:

e) Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear".

Explanation:

<em>if - elseif - else statements work in sequence in which they are written. </em>

  • <em> </em>In case <em>if() statement is true, </em>else if() and else statements will not get executed.
  • In case <em>else if() statement is true</em>, conditions in if() and else if() will be checked and else statement will not be executed.
  • In case <em>if() and else if() both are false</em>, else statement will be executed<em>.</em>

First, let us consider code segment I.

In this, first of all "pea" is checked in if() statement which will look for "pea" only in the String str. So, even if "pearl" or "pear" or "pea" is present in 'str' the result will be true and "pea" will get printed always.

After that there are else if() and else statements which will not get executed because if() statement was already true. As a result else if() and else statements will be skipped.

Now, let us consider code segment II.

In this, "pearl" is checked in if() condition, so it will result in desired output.

Executable code is attached hereby.

Correct option is (e).

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
3 0
1 year ago
1. Write a set of routines for implementing several stacks and queues within a single array. Hint: Look at the lecture material
JulsSmile [24]

Answer:

Out of the two methods The 2nd method is a better option for implementing several stacks and arrays using the single array system this is because Method 2 makes efficient use of the available space

Explanation:

A) Method 1 ( Divide the given single array in the size of n/k.)

  • How to use method 1 to implement several stacks involves :

i)  To implement several stacks through an array (x) is by dividing the array in n/k parts.

ii) The k represents the slots in which the different stacks will be placed and the n represents the size of the array x.

iii) If you need to implement at least two stacks place the first stack in the slot of a [0] to a [n/k - 1], and another stack in the slot of a[n/k] to a[2n/k-1].

note: The  disadvantage of this method is that the use of the space of the array is not much efficient. therefore method 2 is better

  • How to use method 1 to implement queues involves :

i) queues can also be implemented through an array. applying the same method above

ii) Divide the array in slots and place the queues in that slots.

This method has a problem with  the efficient utilization of the space.therefore method 2 is preferred

B) Method 2 ( uses the space efficiently ) uses two more arrays to implement stacks which are : Top_array and Next_array

  • how to use method 2 to implement several stacks

i) Store the indexes of the next item that will also be stored in all stacks in this initial stack

ii)The initial actual array is x[] and this will store the stacks.

iii)Simultaneously with several stacks, the stack which contain the free slots in the array x[] will also be maintained.

iv)  The entries of the Top_array[] will be initialized to -1. This implies that all the stacks are empty.

v)  Firstly the entries of the array Next_array[i] will be initialized to i+1, since all the slots initially are free and are pointed to the next slot.

vi) Initialize The top of the free stack that is maintaining the free slots  as 0.

vii)  The complexity of push () (method to insert an element) and pop () (method to delete an element) operations by using this method is O (1).

  • How to use method 2 to implement several queues

The same method applicable to implementing several stacks is used here but with a difference is the presence of three extra arrays which are :

Front_array[] = indicates the number of queues. This array stores the indexes of the front elements of the stacks.

Rear_array[] = determines the sizeof the array k . This array stores the indexes of the last elements of the stacks.

Next_array[] = The array n indicates the size of the single array say x. This array stores the indexes of the next items that is being pushed.

i) The initial actual array is a[] which will store the queues. The free slots will also be maintained.

ii)The entries of the Front_array[] will be initialized to -1. This means  that all the queues are empty initially

ii) Initially the entries of the array Next_array[i] will be initialized to i+1, since all the slots initially are free and are pointed to the next slot.

iv) Apply The complexity of enqueue ()  and dequeue ()  by using this method is O (1).

4 0
2 years ago
A file named data.txt contains an unknown number of lines, each consisting of a single integer. Write some code that creates two
Damm [24]

Answer:

I am doing it with python.

Explanation:

nums = '9 -8 -7 -6 -5 -4 -2 0 1 5 9 6 7 4'

myfile = open('data.txt', 'w')

myfile.write(nums)

myfile.close()

myfile = open('data.txt', 'r')

num1 = (myfile.read())

num1 = num1.split()

print(num1)

print(type(num1))

for x in num1:

   x = int(x)

   if x < 0:

       minus = open('dataminus.txt', 'a')

       minus.write(str(x) + ' ')

       minus.close()

   elif x>= 0:

       plus = open('dataplus.txt', 'a')

       plus.write(str(x)+' ')

       plus.close()

3 0
1 year ago
Read 2 more answers
Taylor and Rory are hosting a party. They sent out invitations, and each one collected responses into dictionaries, with names o
disa [49]

Answer:

Following are the code to this question:

def combine_guest(guest1, guest2):#defining a method combine_guest that accepts two dictionary

   guest2.update (guest1)#use dictionary guest2 that use update method to update guest2 dictionary

   return guest2#return guest2 dictionary values

Rory_guest= { "Ada":2, "Ben":3, "Dav":1, "Jo":3, "Charry":2, "Terry":1, "bob":4}#defining a dictionary and add value

Taylor_guest = { "Dav":4, "Nan":1, "bobert":2, "Ada":1, "Samantha":3, "Chr":5}#defining a dictionary and add value

print(combine_guest(Rory_guest,Taylor_guest))#calling the combine_guest method

Output:

{'Nan': 1, 'Samantha': 3, 'Ada': 2, 'bob': 4, 'Terry': 1, 'Jo': 3, 'Ben': 3, 'Dav': 1, 'Charry': 2, 'bobert': 2, 'Chr': 5}

Explanation:

In the code a method, "combine_guest" is defined, that accepts two dictionaries "guest1, guest2" inside the method, in which the "guest2" dictionary uses the update method to combine the value of the guest1 dictionary and use a return keyword to return guest2 values.

In the next step, two dictionaries are declared, that holds some values and use a print method to call the "combine_guest" method and prints its return values.  

7 0
1 year ago
Other questions:
  • Ajay wants to read a brief overview about early settlers in the United States. Which type of online text source should he most l
    9·2 answers
  • Which of the following facts determines how often a nonroot bridge or switch sends an 802.1D STP Hello BPDU message?
    14·1 answer
  • Which method allows a computer to react accordingly when it requests data from a server and the server takes too long to respond
    5·1 answer
  • E xercise 17.2.4: The following is a sequence of undo-log records written by two transactions T and U: &lt; START T&gt;; ; &lt;
    15·1 answer
  • You are modeling a small part of an online flight reservation system, according to the following description. A flight is a sing
    11·1 answer
  • In Section 8.5.4, we described a situation in which we prevent deadlock by ensuring that all locks are acquired in a certain ord
    11·1 answer
  • A company decides to relocate its operations to another state in order to take advantage of some new business investment credits
    15·1 answer
  • On a webpage, a _____ provides supplemental material such as social networking feeds and ads. Group of answer choices footer sid
    9·1 answer
  • A credit card company receives numerous phone calls throughout the day from customers reporting fraud and billing disputes. Most
    10·1 answer
  • Finish the program to compute how many gallons of paint are needed to cover the given square feet of walls. Assume 1 gallon can
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!