+ 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

5th Jun 2024, 5:26 PM
Michael Adekanye
Michael Adekanye - avatar
5 odpowiedzi
+ 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
5th Jun 2024, 7:32 PM
Lothar
Lothar - avatar
+ 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.
5th Jun 2024, 7:38 PM
Michael Adekanye
Michael Adekanye - avatar
+ 1
What is the given error?
5th Jun 2024, 5:45 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 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"]
5th Jun 2024, 6:11 PM
Michael Adekanye
Michael Adekanye - avatar
+ 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.
5th Jun 2024, 6:14 PM
Wilbur Jaywright
Wilbur Jaywright - avatar