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
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Els
kherson [118]

Answer:

// here is code in c.

#include <stdio.h>

// main function

int main()

{

// variable to store year

int year;

printf("enter year:");

// read the year

scanf("%d",&year);

// if year>=2101

if(year>=2101)

{

printf("Distant future");

}

//if year in 2001-2100

else if(year>=2001&&year<=2100)

{

   printf("21st century");

}

//if year in 19011-2000

else if(year>=1901&&year<=2000)

{

  printf("20th century");

}

// if year<=1900

else if(year<=1900)

{

  printf("Long ago");  

}

return 0;

}

Explanation:

Read the year from user.After this, check if year is greater or equal to 2101 then print "Distant future".If year is in between 2001-2100 then print "21st century".If year is in between 1901-2000 then print "20th century".Else if year is less or equal to 1900 then print "Long ago".

Output:

enter year:2018                                                                                                            

21st century

7 0
3 years ago
Read 2 more answers
Express 42 as a product  of its prime factor​
salantis [7]
The only way to write 42 as the product
of primes.

Except to change the order of the factors is
2 × 3 × 7. We call 2 × 3 × 7 the prime factorization of 42.
6 0
3 years ago
Read 2 more answers
The risk of carbon monoxide poisoning can be reduced by
lisov135 [29]
A machine. I foget the name but there can be a machine, or fresh air, or turning off your car, or opening doors and getting out when there;s a fire or smoke.
5 0
4 years ago
3 Points
gulaghasi [49]

Answer: Well, In my Opinion it would Be D! because these day people stick together with the internet!. If she adopt her Online business then she would be able to earn profits and also she can serve the people! Slowly people will get to know her business! That will be good for her!

<h3>I hope this works! :)</h3>

3 0
3 years ago
Why is contrast important when designing a web page
Phantasy [73]

Contrast is important when designing a web page for many reasons. One of the most important reasons is because if you don't have contrast, you won't be able to read what is written on the page. Your eyes will have to strain really hard or it just simply won't be possible to read at all. Another really important reason is that contrast makes the web page look visually appealing. Whereas, if you don't have contrast it is all kind of jumbled together. As you can see there is a plethora of reasons contrast is important.

I hope that helps u!!

:)

8 0
3 years ago
Other questions:
  • A ____ port is a connection in which eight data lines transmit an entire byte of data at one moment in time.​
    10·1 answer
  • What is the process called that occurs when you start up your computer? A Download B Restore C Boot D Copy
    12·2 answers
  • How would you like your social media profiles/personas to be treated in the event of your death? why?
    6·2 answers
  • Which of the following is the shortcut key combination for pasting copied text?
    11·2 answers
  • If number is 20, what is printed to the console after this code is executed?
    13·1 answer
  • Explain working principle of computer.​
    5·2 answers
  • Hannah wants to write a book about how scientists and society interact, and she has generated ideas for chapters. Which chapter
    13·1 answer
  • The term _____ refers to an organization of components that define and regulate the collection, storage, management and use of d
    12·1 answer
  • !!! 20 points !!!!!
    15·1 answer
  • What do you think is the most effective way to ensure that code adheres to good coding standards.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!