Penalty Shootout

Hi everyone!

This week we did another soccer activity, a soccer penalty shootout!

This is the link to my finished basic version: https://trinket.io/python/5ea0787701

For this basic version, I watched the instructions in this video, Penalty Shootout Video. It told you exactly everything you needed to do for it. This included setting up the "for" and "while" loops, which can be a little confusing. I figured out that if it's not working the way you want (there's no error code, but it's not doing what you want it to do), then try to go through the code with a fine toothed comb, and verbally talk yourself through the code. If you do this, you can most likely find the spot where you indented wrong or missing a command you need. If you do get a specific error message, then make sure you have all your punctuation (parentheses, commas, brackets, quotes) all in their correct format.

One little thing that I added was for the score to be printed again even when you didn't score. In the original instructions, it only had the score printed if you scored.
Another little thing was I had it print the number of shots you've taken, every time you shoot. I did this because I didn't like that I lost track of the number shot I was on, because it's unlikely you score every single shot.

This is the link to my finished extended version: https://trinket.io/python/3b9ba8ab81
Our first extension task was to display an actual image of the goal, instead of the ASCII art, using the Turtle library. I did this by following the directions on trinket.io after clicking the little picture icon next to the plus icon on the top right part of the coding box.

The second extension task was to validate the user input until they entered the correct information. I did this by using a while loop with an if statement, where if the person did not enter one of the options in the brackets, then an error message would appear and the loop would be restarted.
    if userOption not in ["TL","BL","M","TR","BR","Q"]:
      print("Incorrect response, please choose TL, BL, M, TR, BR.")
      print("")
    else:
      break

Another little requirement was to allow the user to enter lower case, and make it still work. I did this by adding ".upper()" to the end of the input line. This makes whatever they enter into uppercase, therefore making my code work.
      userOption = input("You have 5 penalty shots. Where would you like to shoot? (TL, BL, M, TR, BR, or Q to quit)").upper()

The last extension task was to provide an option to quit the game. I did this by using an if statement and the break command, for the for loop. I had it so that if the user entered "Q", then it had the command break. This makes it move out of the loop, ultimately going to some code I did at the very bottom, which included printing "Game Over" and the user's score.

I was uber busy this week, so I wasn't able to fully devote my attention to trial and error with this project code. I am also still working on pythonroom. All in all, it makes sense after I write it, but it's getting a bit trickier to think of ways to make stuff happen Probably if I got more than 3 hours of sleep, then I might be able to think things through a bit more clearly.

-Mimi

Comments