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
VikaD [51]
3 years ago
6

In this exercise, your function will receive 2 parameters, the name of a text file, and a list of strings. The function will wri

te one line to the text file. The line will contain the fourth character of every string in the list. For any strings that don't have four characters, use x. Be sure to include the newline character at the end.
Computers and Technology
1 answer:
diamong [38]3 years ago
5 0

Answer:

# the function is defined

# it takes 2 arguments: filename and list of string

def solution(filename, listOfString):

   # the file is opened in write mode

   # so that we can write to it

   with open(filename, 'w') as file_object:

       # we loop through the entire list of string

       # this looping help us know what to write to the file

       for each_string in listOfString:

           # if the length of the string is less than 4

           # we write 'x' with a new line

           if len(each_string) < 4:

               file_object.write("x\n")

           # else if the length of the string is greater than equals 4

           # we write the fourth character

           # and also add new line

           else:

               file_object.write(each_string[3])

               file_object.write("\n")

Explanation:

The function is written in Python. It takes two argument; filename and list of string.

It opens the file in write mode and then loop through the list of string. During the loop, we know what to write to the file.

In the length of a string is less than 4; we write 'x' else we write the fourth character in the string. The fourth character has an index of 3 because string uses zero index counting like a string. Starting from zero; 0, 1, 2, 3, 4... the fourth character has an index of 3.

You might be interested in
HELP ME PLEASE !!!!!!!!!!
Snezhnost [94]

Answer:

the last one

Explanation:

8 0
3 years ago
The user cannot use a computer system without.................... software<br><br>​
zheka24 [161]

Answer:

the user cannot use a computer system without hardware and software

4 0
3 years ago
Read 2 more answers
How bridges are built over water
Black_prince [1.1K]
It’s all depending on what method
4 0
2 years ago
Describe your microsoft word skills that need to be improved upon the most.<br><br>​
Ilya [14]
Shortcuts & Formatting Tricks
Mail Merge
Table of Contents
Compare Documents
Track Changes
Using Synonyms
Presenting Tabular data
Managing Header & Footer
Adding Pictures at right position
Automating tasks through Macros
572 viewsView 4 Upvoters
Related Questions (More Answers Below)
5 0
3 years ago
What is the main function of an operating system​
alina1380 [7]

Here are the main functions of an operating system:

1) Manage the resources of the device

The operating system controls how much of each resource is distributed, and it controls things like the processing unit and memory.

2) Establish a interface for the user of the device

The operating system must classify what the classes of the script/code have to do and what they implement.

3) Service application software

The operating system must service each application that is downloaded onto the device. It must balance it's use of storage between apps.

4 0
3 years ago
Other questions:
  • What will be displayed after the following statements have been executed? int x = 15, y = 26, z = 32; x = x + 12; y = y/6; z -=
    15·1 answer
  • You coded the following class: public class N extends String, Integer { }When you compile, you get the following message:N.java:
    9·1 answer
  • Give two separate print statements: one will print your name, the other will print your major. Ensure that both will print on th
    15·1 answer
  • What is one method that can be used to open the Microsoft Word application?
    8·1 answer
  • The building blocks of coded language are called
    11·2 answers
  • A website is a collection of​
    12·2 answers
  • 1. Implement the function dict_intersect, which takes two dictionaries as parameters d1 and d2, and returns a new dictionary whi
    8·1 answer
  • In PowerPoint online what can you add to your presentation from the insert tab
    8·2 answers
  • Light the<br> Spark hop<br> Answer if ur a baddie;)))
    9·2 answers
  • What is one of four key principles of Responsible AIntelligence (AI) vendor serviceIntelligence (AI) vendor serviceI
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!