G
G
Gorduni2021-11-24 11:26:30
Python
Gorduni, 2021-11-24 11:26:30

Output on one line (Python, task from Yandex Practicum): how to comply with the requirement of the task?

I am now going through the free part of the course at Yandex Practicum on Data Analytics.
I'm learning Python from scratch. In Course No. 3 in section No. 2 there is a task (topic "Output on one line").

Task:

The names of the columns that form the "header" of the table are stored in the header list. Display the "header" on the screen in this form:
| Title | EmojiXpress, mln | Instagram, mln | Twitter, mln |
Use a loop and the print() function for this without a line break.
Hint
Follow the algorithm described in the code snippet:
# first type one vertical bar
# < write code here >
for name in header:
# put a space
# < write code here >

# print another name from header
# < write code here >


# add another space and a vertical bar
# < write code here >
Don't forget to include the named argument end='' in every call to print().

My code:

header = ['Название', 'EmojiXpress, млн', 'Instagram, млн', 'Твиттер, млн']
print(' | ', end='')
for name in header:
    print(name,'| ', end='')

The workshop does not want to accept the result produced by my code.
In one of the lines in the tooltip to the task (see above, highlighted in bold) it says "Type the next name from the header."

That is, as I understand it, you need to write some code for each "Header" element separately. Then it is not clear to me: why do we need a cycle?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shandy, 2021-11-24
@Gorduni

header = ['Название', 'EmojiXpress, млн', 'Instagram, млн', 'Твиттер, млн']
string = "|"
for element in header:
    string += f" {element} |"
print(string)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question