+ 2
What's wrong with these codes?
players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 g1 = players[0:2] #Use slicing to create a list for Group 2 g2 = players[2:4] #Use slicing to create a list for Group 3 g3 = players[4:6] print("Group 1:",g1) #display the 1st group print("Group 2:",g2) #display the 2nd group print("Group 3:",g3) #display the 3rd group
5 Respostas
+ 6
Michael Adekanye ,
as already mentioned you can use `2 print statements` to get the task done:
(1. possibility)
print("Group 1:")
print(g1)
(2. possibility)
an other way would be to use an f-string, where you can embed a `new line` sequence `\n` in the string to get a line break.
(3 possibility)
using your current code, you can add an additional argument to the print() function:
print('test', 'this is a new line') # all output in 1 line
now add the argument `sep`, which means `separator`. the default separator for the print() function is a `space` that will separate the regular arguments by a space
print('test', 'this is a new line', sep= '\n')
# output `test` in the first line
# `this is a new line`, in the second line
+ 3
This worked:
print("Group:")
print(g1)
Thanks guys.👍
I feel bad I couldn't figure it out. I feel good I asked for help.
+ 1
What is the given error?
+ 1
It's one of those practice. I wish I could share the image. No stated error.
The only observation in the result tab are: "No input" and
Example of my output is like this:
Group 1: ["Alice", "Bob"]
While expected output is like this:
Group 1:
["Alice", "Bob"]
+ 1
Oh, you’re supposed to have the title “Group X:” and the list appear on separate lines, so don’t put them in the same print statement.