+ 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
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}')
+ 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.
+ 4
You code produces an extra space before each list, not exactly matching the expected output.
0
thanks koli it worked