0
Python: Why is the code not running when I tried to output using F-strings for the "Relay Race" Practice on slicing?
Relay Race" Practice on slicing? https://code.sololearn.com/crapfMaDvBy1/?ref=app
6 ответов
+ 3
The problem is not on the f-strings. I think we just need to add an "\n" before the value of variable inside the f-string.
print(f"Group 1:\n{g1}")
By the way, regarding the "Noteworthy" part of your code. They are indeed different.
🔹Group 1: ["Alice", "Bob"]
is different from
🔹Group 1:
["Alice", "Bob"]
especially in code problems or challenges where the output needs to be in exact format as the expected output.
+ 6
Dr Melchisedec Bankole ,
Your output means you will get the output of the code you built...
Expected output means the predefined output for the problem statement....
That your output should match the expected output...then only all test cases will pass
+ 4
Thank you noteve, mentor Riya, Atif, Wong Hei Ming for all your answers.
I have learned now to always keep to the rule of the game.
Cheers!!!
+ 3
To align your output with the expected output, you can modify your f-string version to remove the square brackets:
# Display the 1st group using f-string without square brackets
print(f"Group 1:\n{', '.join(g1)}")
# Display the 2nd group without square brackets
print(f"Group 2:\n{', '.join(g2)}")
# Display the 3rd group without square brackets
print(f"Group 3:\n{', '.join(g3)}")
This way, the output will match the expected format more closely.
+ 3
As Riya said, your output must be EXACTLY the same as the expected output.
An extra space will prevent you from passing the test.
+ 2
Thanks for your answer.
However, I currently do not understand the difference btw 'Your Output & Expected Output.'
Any explanation please?
Your Output
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']