CIT 591 Assignment 1: Odds and Evens
Fall 2014, David Matuszek
Purposes of this assignment
- To get you started programming in Python
- To get you started using IDLE
General idea of the assignment
Implement a simple gambling game between the human and the player. The rules of the game are this:
- One player is "odd" and the other player is "even."
- Each player begins with a certain amount of money.
- The game consists of a series of bets. In each bet:
- Each player chooses some amount of money, between 1 and the maximum amount that he/she/it can bet..
- The players reveal what they have chosen. If the sum is odd, the "odd player" wins the total amount that was bet; if even, the "even player" takes the total amount that was bet.
- Example: If Odd bets 10 and Even bets 1, the total of 11 is odd, so Odd wins 11 from Even.
- Play continues until one or the other player has less than 2 * the maximum bet, or until the human player decides to quit.
Details
- Start with a brief comment identifying the program, and naming yourself as the author. Remember, comments begin with a
# symbol and continue to the end of the line.
- Next, you will need the line:
import random
This will allow you to use the function random.randint(min, max) in your program.
- Define three variables to hold: (1) the amount of money the human starts with, (2) the amount of money the computer starts with, and (3) the maximum size of each bet (the minimum bet is always
1). Give these variables meaningful names.
- Initially, each player should have
100 (pennies, yen, whatever), and the maximum bet should be 10. Putting these in variables makes it easy to change them, for example, for testing.
- Ask the human whether s/he wants to be
odd or even. Read in one of these words as a string; don't ask for a number.
- This is done once, before betting begins, and isn't changed during the game.
- Play the game, with appropriate input and output to make it clear what is going on. Play continues until either:
- One of the players has less than twice the maximum bet, or
- The human enters a "bet" of zero. This isn't a true bet--no money changes hands--it's just a way of quitting the game.
- Print some appropriate closing message: Congratulations, mocking, whatever.
How to play
The easiest way to have the computer play is to have it choose a random number between 1 and the maximum bet. You can do this with the above random.randint function. This is all that is required in this assignment.
However, people are terrible at being random. For example, a person might tend to choose larger numbers after winning, or smaller numbers after losing. Or the person might choose odd numbers more often than even numbers. With a little effort, you can write a program that wins more often than not. This is not required, and you won't get any extra credit for it, but it makes the game a lot more fun.
Style
Here are some quick style rules you should follow:
- Variables should have meaningful names. Use all lowercase letters, underscores between words.
- Don't scatter numbers throughout your program. It's usually better to give them names, and use the names. (0 and 1 are usually okay, though).
- Use comments (but not too many) to tell the reader what the program is going to do next.
- Put spaces around binary operators:
= + - * / % <= < == != >= >
Grading
Test your program just before turning it in, and don't make any "minor" changes to it after testing--if your program has a syntax error, that will cost a lot of points.
We will try your program to see if there are any obvious errors, and look at it to see if it conforms to the above style rules.
There will be a late penalty of 10 points (out of 100) per day, up to a maximum of 50 points. We reserve the right to refuse to grade programs that are more than a week late.
Due date
Turn your assignment in to Canvas before 6am Friday, September 5.