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
vladimir2022 [97]
3 years ago
9

6. Larger Than n In a program, write a function that accepts two arguments: a list, and a number n. Assume that the list contain

s numbers. The function should display all of the numbers in the list that are greater than the number n.
Computers and Technology
1 answer:
Reika [66]3 years ago
6 0

Answer:

The solution code is written in Python

  1. def largerThanN(myList, n):
  2.    output = ""
  3.    for x in myList:
  4.        if(x > n):
  5.            output += str(x) + " "
  6.    
  7.    print(output)
  8. l = [5, 12, 11, 4, 56, 32]
  9. n = 15
  10. largerThanN(l, n)

Explanation:

Firstly, create a function largerThanN that accepts two arguments, a list (myList) and a number (n) (Line 1).

Next, create a output variable to hold the string of numbers in the list that are greater than the input number n (Line 2).

Create a for loop to traverse through each number in the list and then check if the current x is bigger than n. If so concatenate the x to output string along with a single space " " (Line 4 -6)

After the loop, print the output string (Line 8)

We test the function by using a sample list and n = 15 (Line 10 - 12). The program will display 56 32 .

You might be interested in
6 external parts or peripherals of a computer system and identify which are output and which are input devices.
djverab [1.8K]
A computer peripheral, or peripheral device, is an external object that provides input and output for the computer. Some common input devices include:

keyboard
mouse
touch screen
pen tablet
joystick
MIDI keyboard
scanner
digital camera
microphone
<span>
Some common Output Devices : 
</span>monitor
projector
TV screen
printer
plotter
<span>speakers</span>
3 0
3 years ago
Identify the use of queue in the process of spooling output to a printer.
sashaice [31]

The queue makes sure the printer prints each sheet of paper in order.

6 0
3 years ago
Write a program to help a travelling sales person keep up with their daily mileage driven for business. In your main method, the
Lelu [443]

Answer:

The programming language is not stated;

<em>The program written in C++ is as follows (See Explanation Section for detailed explanation);</em>

#include<iostream>

using namespace std;

int main()

{

 int numdays;

 cout<<"Number of days of mileage: ";

 cin>>numdays;

 int miles[numdays];

for(int i=0;i<numdays;i++)

{

 cout<<"Miles traveled on day "<<i+1<<": ";

 cin>>miles[i];

}

 int total = 0;

 for(int i=0;i<numdays;i++)

{

 total+=miles[i];

}

cout<<"Total mileage traveled: "<<total;

 return 0;

}

Explanation:

This line declares the number of days of mileage

 int numdays;

This line prompts user for days of mileage

 cout<<"Number of days of mileage: ";

This line accepts input from the traveler for days of mileage

 cin>>numdays;

This line creates an array

 int miles[numdays];

The italicized is an iteration that collects the user input for each day

<em> for(int i=0;i<numdays;i++)</em>

<em> {</em>

<em>  cout<<"Miles traveled on day "<<i+1<<": ";</em>

<em>  cin>>miles[i];</em>

<em> }</em>

This line initializes variable to 0

 int total = 0;

The italicized is an iteration that adds up the mileage traveled by the traveler each day  

<em>  for(int i=0;i<numdays;i++)</em>

<em> {</em>

<em>  total+=miles[i];</em>

<em> }</em>

This line prints the total miles traveled

cout<<"Total mileage traveled: "<<total;

5 0
4 years ago
Who was the founder of the location-sharing site Whrrl
Lilit [14]
By Pelago, INC. Founders of Pelago are: Jeff Holden<span> and </span><span>Darren Vengroff.</span>
3 0
3 years ago
Define a function begins_with_line that consumes a string and returns a boolean indicating whether the string begins with a dash
Ksju [112]

Answer:

The program written in python is as follows:

def begins_with_line(userinut):

     while userinut[0] == '-' or userinut[0] == '_':

           print(bool(True))

           break;

     else:

           print(bool(not True))

userinput = input("Enter a string: ")

begins_with_line(userinput)

Explanation:

The program makes use of no comments; However, the line by line explanation is as follows

This line defines the function begins_with_line with parameter userinut

def begins_with_line(userinut):

The following italicized lines checks if the first character of user input is dash (-) or underscore ( _)

<em>      while userinut[0] == '-' or userinut[0] == '_': </em>

<em>            print(bool(True))  </em><em>->The function returns True</em>

<em>            break; </em>

<em>However, the following italicized lines is executed if the first character of user input is neither dash (-) nor underscore ( _)</em>

<em>      else: </em>

<em>            print(bool(not True))  </em><em>-> This returns false</em>

The main starts here

The first line prompts user for input

userinput = input("Enter a string: ")

The next line calls the defined function

begins_with_line(userinput)

<u><em>NB: The program does not make use of if statement</em></u>

8 0
3 years ago
Other questions:
  • Two electronics technicians are looking at the piece of testing equipment shown in the figure above. Technician A says that this
    10·1 answer
  • Write a pseudocode that will take marks of physics, chemistry and math as input, calculates the average and displays output.
    7·2 answers
  • Select the examples that best demonstrate likely employers for Journalism and Broadcasting workers. Check all that apply.
    11·2 answers
  • Which pair of features is relevant when buying a pc?
    9·2 answers
  • A video streaming website uses 32-bit integers to count the number of times each video is played. in anticipation of some videos
    14·1 answer
  • Name 3 supercomputers along with their cost, purpose and the country it is located.​
    15·1 answer
  • Consider the conditions and intentions behind the creation of the internet—that it was initially created as a tool for academics
    12·1 answer
  • How does computer science play a role in art?
    6·1 answer
  • Deirdre has a hearing disability. One of her friends advised her to use real-time text or RTT on her phone. In which of these
    13·1 answer
  • A computer cannot boot if it doesn't have ?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!