Write a python program that reads the first n lines of a text file. Suppose you have a file with all these strings in a file.
(Python)
Task 1
Write a python program that reads the first n lines of a text file.
Suppose you have a file with all these strings in a file.
=========================================================
I love Python
It is very easy to understand the code.
It can code very hard problems easily in python code.
Python programming is the best programming language.
=========================================================
Input :
2
Output :
I love Python Programming.
It is very easy to understand the code.
=========================================================
Hint(1):
Use counter to control line number.
Hint(2):
Use function readlines() to store in a list and then use loop
OR you can use readline() in a loop.
Hint(3):
You might need to use strip() function
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images