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
dezoksy [38]
3 years ago
8

Write a program that Read first n lines of file

Computers and Technology
1 answer:
sergejj [24]3 years ago
7 0

Answer:

Python 2:

with open("datafile") as myfile:

   head = [next(myfile) for x in xrange(N)]

print head

Python 3:

with open("datafile") as myfile:

   head = [next(myfile) for x in range(N)]

print(head)

Both Python 2 & 3:

from itertools import islice

with open("datafile") as myfile:

   head = list(islice(myfile, N))

print head

You might be interested in
Let A be an array of n numbers. Recall that a pair of indices i, j is said to be under an inversion if A[i] > A[j] and i <
AysviL [449]

Answer:

Check the explanation

Explanation:

#include <stdio.h>

int inversions(int a[], int low, int high)

{

int mid= (high+low)/2;

if(low>=high)return 0 ;

else

{

int l= inversions(a,low,mid);

int r=inversions(a,mid+1,high);

int total= 0 ;

for(int i = low;i<=mid;i++)

{

for(int j=mid+1;j<=high;j++)

if(a[i]>a[j])total++;

}

return total+ l+r ;

}

}

int main() {

int a[]={5,4,3,2,1};

printf("%d",inversions(a,0,4));

  return 0;

}

Check the output in the below attached image.

5 0
3 years ago
2x=y t-09 3xX=v 8x0=?+ 87-6x5=
Molodets [167]

Answer:

6

x  

3

 

​  

+x  

2

+2x

Explanation:

4 0
3 years ago
Suppose that an intermixed sequence of push and pop operations are performed on a LIFO stack. The pushes push the numbers 0 thro
nordsb [41]

Answer:

b) 01564 37928

e) 26 8 75 32 901

Explanation:

Pushes and pulls are the computer operations which enable the user to perform numerical tasks. The input commands are interpreted by the computer software and these tasks are converted into numeric values to generate output.

8 0
3 years ago
When would you use conditional formatting on a cell?
Charra [1.4K]
You use conditional formatting on a cell if the numbers are less then zero.
4 0
3 years ago
Which statement are true regarding mainframe computers
Dominik [7]

what are the answer choices?

5 0
4 years ago
Other questions:
  • You’ve been hired to help with installing cable at a new office building for the local branch of the Social Security Administrat
    14·1 answer
  • A network administrator is implementing multifactor authentication for employees who travel and use company devices remotely by
    14·1 answer
  • What are the changes in ios 14.2? What are the benefits of the ios developer program? What is next for Apple? Base your answers
    14·1 answer
  • Explain what might happen if two stations are accidentally assigned the same hardware address?
    15·1 answer
  • Jim works the parts counter for a busy car dealership. When answering the phone, Jim often has trouble answering the customer's
    6·1 answer
  • Which hypervisor works on older pcs without hardware virtualization support?
    9·2 answers
  • What does scarcity force people to do?
    11·1 answer
  • How can a System Administrator quickly determine which user profiles, page layouts, and record types include certain fields? Uni
    14·1 answer
  • What is the full form of HTML?​
    8·2 answers
  • If your earning potential is higher than the cost of your higher education,<br> you will have a
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!