Run update21, if you haven't already, to create the cs21/labs/06. Then cd into your cs21/labs/06 directory and create the python programs for lab 6 in this directory (handin21 looks for your lab 6 assignments in your cs21/labs/06 directory):
$ cd cs21/labs/06 $ pwd /home/your_user_name/cs21/labs/06
Your programs are graded on both correctness and style. Please review
the comments regarding programming style on the main page.
This week you are going to implement and test some functions that
you will use in lab 7. Incrementally implementing
and testing functions is an important way to approach implementing larger
programs. It will save you hours/days of debugging time to implement
and test one function at a time, so this week we are giving you some
practice on this skill.
Because of fall break, we are giving you until the Thursday evening
after fall break to submit this assignment. However, we strongly encourage
you to get it done before it is due (try for Tuesday evening).
What do you want to do next? 1. Spin the Wheel 2. Buy a Vowel 3. Guess the Puzzle 4. Quit, I can't stand this game anymore!
Make a call to PrintMenu from main to test it out. Once you are sure it works, remove the call to PrintMenu from main (this was just for testing purposes).
In main, make a call to GetMenuOption and print out the value it returns:
$ python getmenuoption.py What do you want to do next? 1. Spin the Wheel 2. Buy a Vowel 3. Guess the Puzzle 4. Quit, I can't stand this game anymore! Enter your choice: 1 GetMenuOption returned: 1 $ python getmenuoption.py What do you want to do next? 1. Spin the Wheel 2. Buy a Vowel 3. Guess the Puzzle 4. Quit, I can't stand this game anymore! Enter your choice: hello Hey, hello isn't a valid option. Try again... Enter your choice: a Hey, a isn't a valid option. Try again... Enter your choice: -3 Hey, -3 isn't a valid option. Try again... Enter your choice: 5 Hey, 5 isn't a valid option. Try again... Enter your choice: 2 GetMenuOption returned: 2
Add some calls from main to your IsAVowel function printing out its return value. Test cases where you expect it to return True and cases where you expect it to return False.
Once this works, remove these calls from main (these were just for testing purposes).
Your function should prompt the user to enter a consonant, it should check to see if the user's input is valid, and if so, it should set the corresponding used_letters entry to True (the user has now used this letter), and return the user's guessed letter (a single char string) to the caller.
If the user's input is not valid, your function should print out an error message describing in what way it is not valid, and prompt the user to try entering a consonant again. When you are testing for valid input, make a call to your IsAVowel function when appropriate.
Here are some ways in which a user's input is invalid:
Your function should only return a value after the user enters a valid consonant.
To test your function, add a couple calls from your main function to GetAConsonant and print out its return values. To call this function, you need to create the list of 26 bool values that you pass to it. Once you are satisfied that GetAConsonant is correct, remove these calls from main (these were just for testing).
Here are a few example runs of a working program:
$ python guessconsonant.py Try to guess the consonant I'm thinking of in 5 guesses: Enter a consonant guess: t Nope, T is not right, you have 4 guesses left. Enter a consonant guess: T Hey, you already guessed T Try again... Enter a consonant guess: t Hey, you already guessed T Try again... Enter a consonant guess: a Hey, A is a vowel. Try again... Enter a consonant guess: hello Hey, hello isn't a single letter. Try again... Enter a consonant guess: xxx Hey, xxx isn't a single letter. Try again... Enter a consonant guess: 9 Hey, 9 isn't a letter. Try again... Enter a consonant guess: r Nope, R is not right, you have 3 guesses left. Enter a consonant guess: x You correctly guessed X in 3 tries! $ python guessconsonant.py Try to guess the consonant I'm thinking of in 5 guesses: Enter a consonant guess: t Nope, T is not right, you have 4 guesses left. Enter a consonant guess: r Nope, R is not right, you have 3 guesses left. Enter a consonant guess: s Nope, S is not right, you have 2 guesses left. Enter a consonant guess: p Nope, P is not right, you have 1 guesses left. Enter a consonant guess: q Nope, Q is not right, you have 0 guesses left. You did not guess X better luck next time.