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
frosja888 [35]
1 year ago
12

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer

s that follow. Then, get the last value from the input, which indicates a threshold. Output all integers less than or equal to that last threshold value.
Computers and Technology
2 answers:
Dafna11 [192]1 year ago
4 0

Answer:

def output_ints_less_than_or_equal_to_threshold(user_values, upper_threshold):

 for value in user_values:

     if value < upper_threshold:

         print(value)  

def get_user_values():

 n = int(input())

 lst = []

 for i in range(n):

     lst.append(int(input()))

 return lst  

if __name__ == '__main__':

 userValues = get_user_values()

 upperThreshold = int(input())

 output_ints_less_than_or_equal_to_threshold(userValues, upperThreshold)

Explanation:

meriva1 year ago
3 0

Answer:

package b4;

import java.util.Scanner;

public class TresholdValue {

public static void main(String[] args) {

 // Create an object of the Scanner class to allow for user's input

 Scanner input = new Scanner(System.in);

 // Create a prompt to allow users to enter the set of integers

 System.out.println("Please enter the set of integers, each followed by a space : ");

 // Get the first integer from the set of inputs.

 // Parse the input and convert it into an integer

 // by using the Integer.parseInt() method.

 // Store the result in an integer variable.

 int first = Integer.parseInt(input.next());

 // Create an integer array to hold the other numbers (first number excluded).

 // The array should have a length equal in value to the first number in the set.

 // This has been stored in a variable called "first".

 int[] intarray = new int[first];

 // Create a while loop that populate the intarray with the set of numbers

 int i = 0;

 while (input.hasNext() && i < intarray.length) {

  intarray[i] = Integer.parseInt(input.next());

  i++;

 }

 // Get the last value (threshold) from the intarray.

 // The threshold value is the last element in the array.

 int lastvalue = intarray[intarray.length - 1];

 // Create a prompt before displaying the set of values that are less than or

 // equal to the threshold value.

 System.out.println("Values less than or equal to the threshold value (" + lastvalue + ") are : ");

 // Create a loop to cycle through the array.

 // At each cycle, the element is checked if or not it is less than or equal to

 // the threshold value.

 // If it is less than or equal to, the number is printed.

 for (int j = 0; j < intarray.length - 1; j++) {

  if (intarray[j] <= lastvalue) {

   System.out.print(intarray[j] + " ");

  }

 }

 // (Optional) Close the Scanner object to prevent resource leak

 input.close();

}

}

Explanation:

The program has been written in Java. The source code file has been attached to this response. Please download it for better readability. The code contains comments explaining what goes on on each segment of the code.

Hope this helps!

Download java
You might be interested in
add is a method that accepts two int arguments and returns their sum. Two int variables, euroSales and asiaSales, have already b
Oduvanchick [21]

Answer:

// here is code in Java.

// package

import java.util.*;

// class definition

class Main

{

   // method that return sum of two sale value

   public static int Add(int euroSales,int asiaSales)

   {

       // return the sum

       return euroSales+asiaSales;

   }

   //main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // variables

       int euroSales=100;

       int asiaSales=150;

       int eurasiaSales;

        // call the function

       eurasiaSales=Add(euroSales,asiaSales);

        // print the sum

       System.out.println("total sale is:"+eurasiaSales);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Declare and initialize two variables "euroSales=100" and "asiaSales=150". Declare another variable eurasiaSales. Call the method Add() with euroSales and asiaSales as parameter. This method will add both the value and return the sum.This sum will be assigned to variable eurasiaSales.Then print the sum.

Output:

total sale is:250  

8 0
2 years ago
Given positive integer n, write a for loop that outputs the even numbers from n down to 0. If n is odd, start with the next lowe
seropon [69]

Answer:

The program in Python is as follows:

n = int(input("Enter an integer: "))

if n < 0:

   n = 0

print("Sequence:",end=" ")

for i in range(n,-1,-1):

   if i%2 == 0:

       print(i,end = " ")

Explanation:

This gets input for n

n = int(input("Enter an integer: "))

This sets n to 0 if n is negative

<em>if n < 0:</em>

<em>    n = 0</em>

This prints the string "Sequence"

print("Sequence:",end=" ")

This iterates from n to 0

for i in range(n,-1,-1):

This check if current iteration value is even

   if i%2 == 0:

If yes, the number is printed

       print(i,end = " ")

7 0
1 year ago
You would like the user of a program to enter a customer’s last name. Write a statement thaUse the variables k, d, and s so that
mojhsa [17]

Answer:

1st question:

Use the variables k, d, and s so that they can read three different values from standard input an integer, a float, and a string respectively. On one line, print these variables in reverse order with exactly one space in between each. On a second line, print them in the original order with one space in between them.

Solution:

In Python:

k = input()  #prompts user to input value of k i.e. integer value

d = input()  #prompts user to input value of d i.e. float value

s = input()  #prompts user to input value of s i.e. a string

print (s, d, k)  #displays these variable values in reverse order

print (k, d, s)#displays these variable values in original order

In C++:

#include <iostream>    // to use input output functions

using namespace std;   //to identify objects like cin cout

int main() {    //start of main function

  int k;   //declare int type variable to store an integer value

  float d; //  declare float type variable to store a float value

  string s;   //  declare string type variable to store an integer value

  cin >> k >> d >> s;    //reads the value of k, d and s

  cout << s << " " << d << " " << k << endl;     //displays these variables values in reverse order

  cout << k << " " << d << " " << s << endl;   } // displays these variable values in original order

Explanation:

2nd question:

You would like the user of a program to enter a customer’s last name. Write a statement that asks user "Last Name:" and assigns input to a string variable called last_name.

Solution:

In Python:

last_name = input("Last Name:")

# input function is used to accept input from user and assign the input value to last_name variable

In C++:

string last_name;  //declares a string type variable named last_name

cout<<"Last Name: ";  // prompts user to enter last name by displaying this message Last Name:

cin>>last_name; // reads and assigns the input value to string variable last_name

The programs alongwith their outputs are attached.

6 0
2 years ago
If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
Nimfa-mama [501]

Answer:  

For 32 bits Instruction Format:

OPCODE   DR               SR1                   SR2      Unused bits

a) Minimum number of bits required to represent the OPCODE = 3 bits

There are 8 opcodes. Patterns required for these opcodes must be unique. For this purpose, take log base 2 of 8 and then ceil the result.

Ceil (log2 (8)) = 3

b) Minimum number of bits For Destination Register(DR) = 4 bits

There are 10 registers. For unique register values take log base 2 of 10 and then ceil the value.  4 bits are required for each register. Hence, DR, SR1 and SR2 all require 12 bits in all.  

Ceil (log2 (10)) = 4

c) Maximum number of UNUSED bits in Instruction encoding = 17 bits

Total number of bits used = bits used for registers + bits used for OPCODE  

     = 12 + 3 = 15  

Total  number of bits for instruction format = 32  

Maximum  No. of Unused bits = 32 – 15 = 17 bits  

OPCODE                DR              SR1             SR2              Unused bits

  3 bits              4 bits          4 bits           4 bits                17 bits

7 0
1 year ago
Lynn runs the locate command and the results include many files from a directory that she doesn't want to include in her search.
Zinaida [17]

Answer:

C) /etc/updatedb.conf

Explanation:

The locate command actually uses the configuration file located at /etc/updated.conf.

5 0
1 year ago
Read 2 more answers
Other questions:
  • Which perspective is usually used in process simulations?
    6·1 answer
  • Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user shoul
    13·1 answer
  • For drivers under 21, the penalties for driving with an illegal BAL include _____.
    5·2 answers
  • For any element in keysList with a value greater than 50, print the corresponding value in itemsList, followed by a space. Ex: I
    8·1 answer
  • Write an expression that executes the loop body as long as the user enters a non-negative number. Note: If the submitted code ha
    7·1 answer
  • Print "userNum1 is negative." if userNum1 is less than O. End with newline Convert userNum2 to 0 if userNum2 is greater than 8.
    10·1 answer
  • int decode2(int x, int y, int z); is compiled into 32bit x86 assembly code. The body of the code is as follows: NOTE: x at %ebp+
    5·1 answer
  • The Boffo Balloon Company makes helium balloons. Large balloons cost $13.00 a dozen, medium-sized balloons cost $11.00 a dozen,
    13·1 answer
  • Which is true regarding pseudocode
    8·1 answer
  • 1.21 LAB: Divide by x
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!