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
sergiy2304 [10]
3 years ago
12

Write a program that first reads in the name of an input file and then reads the input file using the file.readlines() method

Computers and Technology
1 answer:
weeeeeb [17]3 years ago
3 0

Using the computational language in python we have to use it to write to a file and read with the code.

<h3>Writing this code in python we have:</h3>

<em>filename = input()</em>

<em>file = open(filename)</em>

<em>lines = file.readlines()</em>

<em>data = {}</em>

<em>for i in range(0, len(lines), 2):</em>

<em>    num_seasons = int(lines[i].strip())</em>

<em>    show = lines[i + 1].strip()</em>

<em>    if num_seasons not in data:</em>

<em>        data[num_seasons] = []</em>

<em>    data[num_seasons].append(show)</em>

<em>file.close()</em>

<em>file_writer = open('output_keys.txt', 'w')</em>

<em>titles = []</em>

<em>for num_seasons in sorted(data):</em>

<em>    shows = []</em>

<em>    for show in sorted(data[num_seasons]):</em>

<em>        titles.append(show)</em>

<em>    file_writer.write(str(num_seasons) + ': ' + '; '.join(data[num_seasons]) + '\n')</em>

<em>file_writer.close()</em>

<em>file_writer = open('output_titles.txt', 'w')</em>

<em>for title in sorted(titles):</em>

<em>    file_writer.write(title + '\n')</em>

<em>file_writer.close()</em>

See more about python at brainly.com/question/18502436

#SPJ1

You might be interested in
Create a function called biggestNum that returns the largest number in an array of integers. The function is passed only one par
goldenfox [79]

This is for Python

def biggestNum():

   array = []

   for i in range(8):

       number = int(input('Enter number: '))

       array.append(number)

   

   return max(array)

print(biggestNum())

5 0
3 years ago
An anchor tag can be coded using which two attributes?
IceJOKER [234]

Answer:

21212122121221212211212121212212121Explanation:

4 0
2 years ago
Write two versions of a program that reads a sequence of positive integers from the user, calculates their geometric mean, and p
givi [52]

Answer:

1)

n = int(input("Please enter the length of the sequence: "))

print("Please enter your sequence")

product = 1

for i in range(n):

   val = int(input())

   product *= val

print("The geometric mean is: %.4f"%pow(product,1/n))

2)

print("Please enter a non-empty sequence of positive integers, each one is in a separate line. End your sequence by typing done:")

product = 1

val = input()

n = 0

while(val!="done"):

   product *= int(val)

   n += 1

   val = input()

print("The geometric mean is: %.4f"%pow(product,1/n))

Explanation:

4 0
3 years ago
What is known as networking in the IT field?
Sidana [21]

Answer:

r u Kate tell me plz I love u baby tell me please

4 0
3 years ago
Where would you go to add fractions to a document in adobe indesign
prisoha [69]

Just select the fraction text and choose Open Type > Fractions from the Character panel menu.

5 0
3 years ago
Other questions:
  • Suppose sum and num are int variables, and the input is 18 25 61 6 -1
    11·2 answers
  • Attempting to determine a password that is not known to the attacker is often called ____.
    13·1 answer
  • __________ is when a person feels compelled to acquire and abuse a drug despite the harm it causes him or her personally, and de
    14·1 answer
  • What additional information could you add to a sketch to provide other team members with a more accurate design drawing?
    9·1 answer
  • What does the regular expression [a-z0-9\-] mean?
    8·1 answer
  • Respond to the following in three to five sentences. Select the workplace skill, habit, or attitude described in this chapter th
    15·2 answers
  • Which function returns a valid value without any arguments?
    14·2 answers
  • Which of the following is the shortcut key combination for pasting copied text?
    11·2 answers
  • Why does everyone refer to dogs as being loyal
    11·2 answers
  • When Tim Berners-Lee developed the first specifications, protocols, and tools for the World Wide Web in 1993, his employers at C
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!