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
ArbitrLikvidat [17]
3 years ago
7

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.
It should be like as this sample run follows.

Enter the input file name: quotes.xtxt
I cannot open the file quotes.xtxt - Please check the name and try again.
Enter the input file name: quotes.txt
The file has 16 lines.
Enter a line number [0 to quit]: 1
1: Hakuna Matata!
Enter a line number [0 to quit]: -1
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 16
16: Just keep swimming!
Enter a line number [0 to quit]: 17
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 5
5: It's kind of fun to do the impossible.
Enter a line number [0 to quit]: A
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: $
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: 4
4: To infinity and beyond!
Enter a line number [0 to quit]: 0
Computers and Technology
1 answer:
pickupchik [31]3 years ago
7 0

Answer:

Explanation:

iname=input("Enter the file name: ")

inputfile=open(iname,'r')

lines=[]

for line in inputfile:

lines.append(line)

inputfile.close()

print("The file has ",len(lines)," lines")

while True:

linenumber=int(input("Enter the line number or 0 to quit: "))

if linenumber==0:

break

elif linenumber > len(lines):

print("Error: line number must be less than ", len(lines))

else:

print(linenumber, " : ", lines[linenumber - 1])

You might be interested in
Polymorphism means (Points : 2) many forms
Pavel [41]

Answer:

many forms

Explanation:

Polymorphism is a construct in object oriented programming which means multiple forms.For example: Suppose I have a function which performs the add operation on two integers and another function with the same name which concatenates 2 given strings:

  • int add ( int a, int b);
  • string add ( string a , string b)

The two functions represent polymorphic forms of the add function. The function to be invoked at runtime is determined by the runtime argument type.

For example , add (2,3) will invoke int add ( int a, int b);

Similarly, add("hello","world") will invoke string add ( string a , string b);

6 0
2 years ago
PLSSSSS HELPP!! Population biologists are concerned about invasive species such as the zebra mussel found in North American wate
elixir [45]

Answer: A.The introduced species compete for resources more effectively than native species.

Explanation:

An introduced species is also called the exotic species and this is an organism which is not a native organism or specie and therefore isn't native to the place but rather it's being transported to the place through the activities of human being.

When the introduced species are introduced to a particular area, they compete with the natives for the available resources and often do this more effectively than the other native species.

Therefore, the correct option is A.

4 0
3 years ago
g Assignment 8: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon as input, a
zavuch27 [327]

Answer:

miles_gallon = float(input("Enter car's miles/gallon: "))

dollars_gallon = float(input("Enter gas dollars/gallon: "))

print("Gas cost for 20 miles is $", (20 / miles_gallon) * dollars_gallon)

print("Gas cost for 75 miles is $", (75 / miles_gallon) * dollars_gallon)

print("Gas cost for 500 miles is $", (500 / miles_gallon) * dollars_gallon)

Explanation:

*The code is in Python.

Ask the user to enter the car's miles/gallon and gas dollars/gallon

Calculate the gas cost for 20 miles, divide 20 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 75 miles, divide 75 by miles_gallon and multiply the result by dollars_gallon, then print it

Calculate the gas cost for 500 miles, divide 500 by miles_gallon and multiply the result by dollars_gallon, then print it

5 0
2 years ago
hãy soạn thảo một bản hợp đồng chuyển giao hoặc thu thập thông tin nhằm bán/ mua/ trao đổi thông tin/ tài liệu giữa hai tổ chức.
mariarad [96]

Explanation:

wuwhwhwhshahahabahsgsgagsgshshshsjeushsjsjsiajausudid

idirieieirieeie

iep

7 0
2 years ago
Combinations of spaces and special characters can be used in domain names of uniform resource locators (urls).
iris [78.8K]

A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.

The statement that combinations of spaces and special characters can be used in domain names of uniform resource locators (URLs) is false. Correct answer: B

The specifications for URLs are clealy defined by The Internet Engineering Task Force (IETF).

7 0
2 years ago
Read 2 more answers
Other questions:
  • To execute a prepared SQL statement, you can use the _______ and execute methods of the PDOStatement object to set parameter val
    9·1 answer
  • Answers please !!!!!!!!!!!!!!!!!!!!!!!!!!!
    8·1 answer
  • Nick is working on a new graphic for one of his company’s clients and is having an issue with the color on his screen. The clien
    8·1 answer
  • You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly
    11·1 answer
  • Which of the following events would most likely produce an earthquake
    10·1 answer
  • Use the word bank to identify each description.
    6·1 answer
  • The show ip dhcp binding command displays _____. (Points : 5) the MAC table cache information
    7·1 answer
  • Name all mario kart games in order
    15·2 answers
  • What Is The First Computer Brought In Nepal ? <br>​
    10·1 answer
  • What is a symbol such as a heavy dot or another character that precedes a text in a power point
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!