+ 1

Nothing happens when I run code for coding challenge

I'm in the first coding project for the "Python for Data Science" course (the basketball players one), and when I run my code, nothing happens. The Results tab doesn't show anything except "Test Case 1" which is hidden. I don't see any output or even errors. For reference, this is my code: players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players)/len(players) diffs = [(p-mean)**2 for p in players] variance = sum(diffs)/len(diffs) std = variance**-2 players_in_std = [p for p in players if (mean-std)<=p<=(mean+std)] print(len(players_in_std))

30th Nov 2021, 4:07 AM
Linus
Linus - avatar
1 Réponse
+ 1
# Hi! Debug your code in playgrund! Print all partial results! Look at them! Find the errors! # - - - - - - - - - - - - - - - - - - players = [180, 172, 178, 185, 190, 195, 192, 200, 210, 190] mean = sum(players) / len(players) print(f"{mean = }") diffs = [(p - mean) ** 2 for p in players] print(f"\n{diffs = }\n") variance = sum(diffs) / len(diffs) # std = variance ** (-2) # Something wrong here! std = variance ** (1/2) # Try this! print(f"{variance = }\n{std = }\n{mean - std = }\n{mean + std = }") players_in_std = [p for p in players if (mean - std) <= p <= (mean + std)] print(f"\n{players = }") print(f"{players_in_std = }") print(f"{len(players_in_std) = }") # - - - - - - - - - - - - - - - - - - # Put the code in playground and start to work! Copy the hole code in this message to playground! https://code.sololearn.com/cG7ijtqWp4t5/?ref=app
30th Nov 2021, 4:43 AM
Per Bratthammar
Per Bratthammar - avatar