I'm trying to create a program that asks a user how many lines of the text file they want to see. I need to make it so if the user enters more than the number of lines, then I have in the file that it prints out the entire file.
Below is the code I have so far but the problem I am currently having is it only prints out the first line of the text no matter what number I enter.
Using Python 3.4:
def readFile():
"""retrieve the file my_data.txt"""
try:
textFile = open("my_data.txt","r")
return textFile
except:
print("The file does not exist")
return
def readLines():
textFile = open("my_data.txt","r")
file_lines = textFile.readline()
print(file_lines)
#main
while True:
cmd = int(input("\nEnter the number of lines you would like to read: "))
readLines()