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
_______________ ________________ have human editors that evaluate, select, and organize websites into a hierarchy of categories.
faust18 [17]

Answer:

wtaf dude?! at least do so on you're own questions! now I lost all of my answers thanks to you bro -_-

Explanation:

6 0
2 years ago
What is the output?
olga55 [171]

Answer:

The output is 28

Explanation:

Required

Determine the output of the code segment

The first line initializes "answer" to 0

The next two lines iterate through lists [2,4] and [3,5

Each of these lists have two elements; So, the number of iterations is 2 * 2 i.e. 4.

In the first iteration

numA = 2, numB = 3, answer = 0

So:

answer = answer + numA + numB= 0 + 2 + 3 = 5

In the second iteration

numA = 2, numB = 5, answer = 5

So:

answer = answer + numA + numB= 5 + 2 + 5 = 12

In the third iteration

numA = 4, numB = 3, answer = 12

So:

answer = answer + numA + numB= 12 + 4 + 3 = 19

In the fourth iteration

numA = 4, numB = 5, answer = 19

So:

answer = answer + numA + numB= 19 + 4 + 5 = 28

Lastly, the value of "answer" is printed

<em>Hence, the output is 28</em>

7 0
3 years ago
Buying an existing business
HACTEHA [7]
Goin to make great profit
8 0
2 years ago
As a final lesson to her team, Katie shows them a job that has already been preflighted and is now getting ready to be sent to t
Vsevolod [243]

Answer:

Printed

Explanation:

The job was finished and sent to the printer. In the printer, you have to waite to be printed

5 0
3 years ago
What was the first e-commerce service?
docker41 [41]

The first e-commerce service would be A)Banking. Hope this helps.

8 0
3 years ago
Other questions:
  • What three components make up a film camera?
    14·2 answers
  • A computer that delivers requested webpages to your computer or mobile device is a(n) _________.
    9·1 answer
  • AddAll - Adds all the doubles in the string with each other. Note every double is separated by a semi-colon. AddAll("1.245;2.9")
    6·1 answer
  • You change a document that is saved on your computer by cutting text from the document what happens to the text when you preform
    5·1 answer
  • I have this assignment due TONIGHT BEFORE 10PM! Please help. 50 points for whoever will help!! Here is the assignment.
    7·1 answer
  • Which of these is one of the primary concerns for protecting your family when online?
    9·2 answers
  • When specifying keywords to conduct an internet search, which of the following parts of speech will be the most useful??
    6·1 answer
  • Which term refers to the blank areas surrounding a document page? *
    15·1 answer
  • he wants to customize the operating system to meet his needs. what types of tools should he use, and what can he do with each?
    6·1 answer
  • [C++] 4.17 LAB: Print string in reverse Write a program that takes in a line of text as input, and outputs that line of text in
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!