Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

B R
B R
2,660 Points

A Number Guessing Game - Storing Attempts to a List

Hello,

I am writing my code in Workspaces.

Does Workspaces not allow you to store lists or am I likely doing something wrong?

I seem to be unable to save scores to a list in order to calculate mean, median, and mode.

The list is outside of the function where I determine the len or count of the number of guesses made by a player while running the program. I then append that len or count to the list that is located outside of the function.

My stats never change. The number of guesses in that individual game are the same as the mean, median, and mode calculated from the list where I have attempted to store scores to individual games.

Thanks, B

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

It may be helpful to share a link to your workspace snapshot. Use the icon in upper right corner of the workspace window to creat snapshot.

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Hey B R, there is some flow control issues with the game.

  • if one wins the game, there is no path to restart the game. The break in line 93 exits the while loop and start_game ends. This leads to always getting statistics on one data point.
  • Simply removing the break loops back to the top of the while loop and fails to set a new target number.
  • A better mechanism is needed to close out one game and start another.

It is a bit concerning that there are so many recursive calls to start_game() from with start_game. One suggestion would be to separate the game play from the play again code. Leave the actual game in start_game. Call start_game from an external while loop that asks after game completion if they want to play again, if so, call start_game() again, if not, print statistics. This removes the recursive calls.

If a number is out of range or not a number, it might work better to loop back to input to ask again instead of restarting the game, further removing recursive calls.

Post back if you need more help. Good luck!!

B R
B R
2,660 Points

Thank you so much for your time and thoughtful feedback! I will work with those suggestions and hopefully make some progress.

Thanks, BR

B R
B R
2,660 Points

https://w.trhou.se/ejo03huykc

Thank you for your time!

I am currently working in "guessing_game.py" and not "guessing.py"