+ 2

relay race doesn't work without spaces

so my code is players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 group1 = players[0:2] group2 = players[2:4] group3 = players[4:7] # Display the groups print("Group 1:", group1) print("Group 2:", group2) print("Group 3:", group3) #display the 3rd group but it gives me an error because Group 1: ['Alice', 'Bob'] Group 2: ['Charlie', 'David'] Group 3: ['Eve', 'Frank'] Expected Output Group 1: ['Alice', 'Bob'] Group 2: ['Charlie', 'David'] Group 3: ['Eve', 'Frank']

3rd Sep 2023, 4:39 PM
Abood Maswadeh
18 Answers
+ 7
Abood Maswadeh , i am not quite sure, but i guess that you want to avoid a `space` in front of the line with the names. this issue is created when using a comma separated arguments list in print() function. we can avoid this, by adding the `sep=...` option like: ... print("Group 1:\n", group1, sep="") ... sep="" defines a new separator (in this case it's an empty string) when doing output with print(). by default print() is using one space at each comma position.
4th Sep 2023, 3:33 PM
Lothar
Lothar - avatar
+ 5
Abood Maswadeh , Add '\n' for showing output in new line... Here take a look, https://code.sololearn.com/c73pFraWUkin/?ref=app
3rd Sep 2023, 5:13 PM
Riya
Riya - avatar
+ 4
S. Pooja sri 2005 , the first and second line of each group is perfectly aligned, but the issue with your code is, that each line starts with a space. this should not be. we can use an output like: ... print("Group 1:\n",group1, sep="") ... > ? what does sep="" mean ? when using output with comma separated arguments, python inserts one space at each comma position. but we can define our own separator, which should be an empty string in this case. this makes both lines start at thd leftmost position without a leading space.
24th Sep 2023, 7:13 PM
Lothar
Lothar - avatar
+ 2
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 I donr understand why my code doesnt work
15th Sep 2023, 2:27 AM
Junior Luiz
Junior Luiz - avatar
+ 2
#This is my solution players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 group1 = players[0:2] group2 = players[2:4] group3 = players[4:6] # Display the groups print("Group 1:") print(group1) print("Group 2:") print(group2) print("Group 3:") print(group3)
30th Sep 2023, 4:09 AM
Jens-Andreas Hoheisel
Jens-Andreas Hoheisel - avatar
+ 2
THE ANSWER 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:7] print("Group 1:") #display the 1st group print(g1) print("Group 2:") #display the 2nd group print(g2) print("Group 3:") #display the 3rd group print(g3)
5th Oct 2023, 5:34 PM
Cryptic X
Cryptic X - avatar
+ 1
Here's the answer ✅ #code by kelluuh 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,sep="") #display the 1st group print("Group 2:\n",g2,sep="") #display the 2nd group print("Group 3:\n",g3,sep="") #display the 3rd group
14th Oct 2023, 9:33 PM
Kelvin Ronoh
Kelvin Ronoh - avatar
0
I think the problem is in the third line actually group 3 I checked it it worked for me group1 = players[0:2] group2 = players[2:4] group3 = players[4:6]
3rd Sep 2023, 7:38 PM
Fateme Biglari
Fateme Biglari - avatar
0
Plz can anyone send proper code??
21st Sep 2023, 1:23 AM
Pranay PRASHANT NAIK
Pranay PRASHANT NAIK - avatar
0
play = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] group1=play[0:2] #Use slicing to create a list for Group 2 group2=play[2:4] #Use slicing to create a list for Group 3 group3=play[4:6] print(" Group 1:\n",group1) #display the 1st group print(" Group 2:\n",group2) #display the 2nd group print(" Group 3:\n",group3) #display the 3rd group I have the expected output but it gives an error The expected output and my output are perfectly same
22nd Sep 2023, 2:07 AM
S. Pooja sri 2005
S. Pooja sri 2005 - avatar
0
How can I get rid of this problem sololearn help to rectify this problem
22nd Sep 2023, 2:10 AM
S. Pooja sri 2005
S. Pooja sri 2005 - avatar
0
players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 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:") #display the 1st group print (g1) print("Group 2:") #display the 2nd grou print (g2) print("Group 3:") #display the 3rd group print (g3)
4th Oct 2023, 9:02 PM
Nagi Suliman Ibrahim
Nagi Suliman Ibrahim - avatar
0
solution - players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] # Create 3 lists with 2 players each # Use slicing to create a list for Group 1 group1 = players[0:2] # Use slicing to create a list for Group 2 group2 = players[2:4] # Use slicing to create a list for Group 3 group3 = players[4:6] print("Group 1:") print(group1) print("Group 2:") print(group2) print("Group 3:") print(group3)
16th Oct 2023, 1:04 AM
Vinothini Saththiyaselan
Vinothini Saththiyaselan - avatar
0
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(f"Group 1:\n{g1}") #display the 1st group print(f"Group 2:\n{g2}") #display the 2nd group print(f"Group 3:\n{g3}") #display the 3rd group #this is the answer
23rd Nov 2023, 3:04 PM
EZE VICTOR CHIDIOGO
EZE VICTOR CHIDIOGO - avatar
0
Here is the Correct Code!!! Try it out 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,sep="") #display the 1st group print("Group 2:\n",g2,sep="") #display the 2nd group print("Group 3:\n",g3,sep="") #display the 3rd group
12th Dec 2023, 2:34 PM
Demilade Howells
Demilade Howells - avatar
0
players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 group1 = players[0:2] group2 = players[2:4] group3 = players[4:6] # Display the groups print("Group 1:") print(group1) print("Group 2:") print(group2) print("Group 3:") print(group3)
15th Dec 2023, 3:56 PM
Amulya Vemula
0
here in this code we will be finding error becoz most the people dosen't put sep=''" in the print statement .So here is the solution for it ..... players = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank"] #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 group1 = players[0:2] group2 = players[2:4] group3 = players[4:6] # Display the groups print("Group 1:", group1,sep='') print("Group 2:", group2,sep="") print("Group 3:", group3sep="") #display the 3rd group
5th Jan 2024, 1:09 AM
Meghana Mekala
Meghana Mekala - avatar
0
#NO ERROR ALL TESTCASE PASSED #Create 3 lists with 2 players each #Use slicing to create a list for Group 1 players = ['Alice','Bob','Charlie','David','Eve','Frank'] group1 = players[0:2] group2 = players[2:4] group3 = players[4:6] # Display the groups print('Group 1:\n',group1,sep="") print('Group 2:\n',group2,sep="") print('Group 3:\n',group3,sep="")
8th Jan 2024, 3:53 PM
Mohammed Afzal Hussain
Mohammed Afzal Hussain - avatar