Question
Having issues with this assignment but it keeps giving me an error when i check it. The screenshot shows the sentence in red that is
Having issues with this assignment but it keeps giving me an error when i check it. The screenshot shows the sentence in red that is creating error when it checks it.
Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number
Tasks example.txt navigate.py >_ Terminal + = Program produces correct output given input 3 out of 4 checks passed. Review the results below for more details. 2 filename = input("example.txt") 3 file = open("example.txt") 4 count = 0 5 for line in file: 6 count = count + 1 7 print("The file has "+stricount)+" lines."); 8 file.close() 9 while True: 10 try: n = int(input("Enter a line number 10 to quitl: ")) Lineno = 0 break; 14 except ValueError: Print("Try again. Line number must be between B and "+5tricount)) 16 while n !=: Checks 72 Custom Test. Complete Delete file at start Custom Test . Complete Create file for test Test Case Incomplete Test program Input test.txt if n and n = count: file = open("example.txt") for line in file: lineno = lineno + 1 if lineno == n: print(line) else: print("Try again. Line number must be between 0 and "+5tr count)) while True: try: n = int(input("Enter a line number (0 to quit]: ")) lineno = @ break; except ValueError: print("Try again. Line number must be between 0 and "+str(count)) Output example.txttest.txt The file has 5 lines. Enter a line nurber [@ to quit]: 3 To be, or not to be that is the question: Enter a line number [0 to quit]: 1 The slings and arrows of outrageous fortune, Enter a line nurber [@ to quit]: Results The file has 5 lines. The slings and arrows of outrageous fortune, To be, ar not to be that is theStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started