+ 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']
18 Réponses
+ 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.
+ 5
Abood Maswadeh ,
Add '\n' for showing output in new line...
Here take a look,
https://code.sololearn.com/c73pFraWUkin/?ref=app
+ 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.
+ 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
+ 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)
+ 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)
+ 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
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]
0
Plz can anyone send proper code??
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
0
How can I get rid of this problem sololearn help to rectify this problem
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)
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)
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
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
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)
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
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="")