Python: Why is the code not running when I tried to output using F-strings for the "Relay Race" Practice on slicing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

10th Nov 2023, 2:19 PM
Dr Melchisedec Bankole
Dr Melchisedec Bankole - avatar
6 Answers
+ 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.
10th Nov 2023, 2:24 PM
noteve
noteve - avatar
+ 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
10th Nov 2023, 2:39 PM
Riya
Riya - avatar
+ 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!!!
10th Nov 2023, 4:58 PM
Dr Melchisedec Bankole
Dr Melchisedec Bankole - avatar
+ 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.
10th Nov 2023, 3:01 PM
Atif
Atif - avatar
+ 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.
10th Nov 2023, 3:07 PM
Wong Hei Ming
Wong Hei Ming - avatar
+ 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']
10th Nov 2023, 2:30 PM
Dr Melchisedec Bankole
Dr Melchisedec Bankole - avatar