You’ll spend the next hour and a half on your first programming project. I’ll walk through some of the first steps together, then you can strike out on your own. Don’t worry, though—I’m here to help if you get stuck or confused!

When you’re done with your program, please Submit it using the green button in the top right corner and let me know. I will check over it and let you know if there are any bugs.

If your program doesn’t need fixing and there are more than fifteen minutes left before the end of lab time, I’ll ask you to work on one the bonus exercise below.

When we write a program, we have certain expectations about how users will interact with our program. For example, if we tell them to enter a number between 1 and 10, we expect to get 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10. Of course, users don't always cooperate, and if you're not careful, your program might crash due to user error.

For example, our makeChoice() function expects the user to enter a number. It can handle if they enter a number that's too big or too small, but not if they enter a letter or other character. If you want to be careful and avoid an error if the player doesn't enter a number, you can use this code:

def makeChoice(numChoices):
 choice = 0
 while choice < 1 or choice > numChoices:
 choice = input('What do you do?')
 try:
 # Convert the input to an integer
 choice = int(choice)
 except:
 print("That's not a number.")
 choice = 0
 return choice

The code under try tests the user input, converting it to an integer if possible. But if the input is a letter or other character, int() will raise an error message. Instead of crashing your program, the except statement catches the error and runs your alternative code.

You can use try/except structures to catch user error or other unexpected errors in your program. This is a good way to practice making your programs more robust!