+ 1

Hello guys is there a problem in this Python code of mine. it gives the expected out put but still i cant get the marks.

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:\n",g1) #display the 1st group print("Group 2:\n",g2) #display the 2nd group print("Group 3:\n",g3) #display the 3rd group

6th Nov 2023, 10:59 PM
John
John - avatar
4 Respostas
+ 3
John , here are some hints how we can achieve the expected output in one line of code: the reason for this single space at the beginning of the second line: when using comma separated arguments in print() function, python is inserting a space by default. > to avoid this, we can use: this is overwriting the default value for the separator by an empty string. print("Group 1:\n", g1, sep='') > second option is to use f-string instead: print(f'Group 1:\n{g1}')
7th Nov 2023, 4:03 PM
Lothar
Lothar - avatar
+ 5
I also got the same problem initially! Print g1, g2, g3 in different lines means use another print function to output g1 and same for g2 and g3.
7th Nov 2023, 12:32 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 4
You code produces an extra space before each list, not exactly matching the expected output.
7th Nov 2023, 1:14 AM
Wong Hei Ming
Wong Hei Ming - avatar
0
thanks koli it worked
7th Nov 2023, 10:32 AM
John
John - avatar