Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

1336 MidTerm Examination

General Statement

You must write this examination starting with either the Template for Simple Programs (chapters 1-4).py or starter.py. You earn up to 60% by correct operation and up to 40% with good style, readability, and documentation. Refer to the Style Requirements.pdf and Scoring Criteria.pdf documents posted in Blackboard for specific requirements.  Use the solution to Assignment 1 for reference and code if desired.

Problem Summary

In this examination, we expand on the Monopoly game from Assignment 1.  A big change from Assignment 1 is using numbers instead of strings this sets up a lot of possibilities later.  The major changes are:

1.   Player and property locations are now called squares, and they are numbers

2.   Property owner is now a number: 0 = unowned, 1 = player1, 2 = player2

3.   Players move by adding their move number to their square

4.   When landing on square, if the square property is unowned the player buys it, otherwise the player pays rent to the owner

5.   The header and status lines should still line up in columns; see samples on the next page.

Steps


Note that steps 1 and 2 are already in starter.py.


1.   Set constants for PLAYER1_MOVE (1) PLAYER2_MOVE (3) HIGHEST_SQUARE (3), NUM_TURNS (5)

2.   Declare all variables (see Assignment 1 solution for examples of the variable names)

a.   Each player has a name (str) , a square (int), and money (int)

b.   Each property has a name (str) , a square (int), a price (int), a rent (int), and an owner (int)

c.    Include a new fourth property, property0, with those same features

3.   Set initial variable values

a.   Squares:  players start at 0, property0 is 0, property A is 1, property B is 2, property C is 3

b.   property0 has name “Go”, square 0, price 200, rent 0, owner 0

c.    Player names and money, are the same as in Assignment 1, starting square is 0

d.   Property names, price, and rent are the same as in Assignment 1, owners are 0

4.   Display header line

5.   For the number of turns

a.   Move player1

i.   Move and adjust the player’s square.  To loop around the board, use this formula:

player1_square = (player1_square + PLAYER1_MOVE) % (HIGHEST_SQUARE + 1)

( I leave it to you to see why this keeps the player within the board squares)

ii.   Check which property has this square number: 0 (it’s Go): add $200 to player’s money

1, 2, or 3: check who owns it

1.   Unowned:  buy it  (remember: property owner is a number, not player name)

2.   Owned by other player:  pay rent to the other player

iii.   Display a status line

b.   Move player2, follow all the steps as with player1, adjusting accordingly

6.   Display final status line

Sample of header and status lines

dog

$1440

square

1

hat

$1425

square

0

Mediterranean Ave.    Baltic Ave.

2                                     0

Reading Railroad

1

If you use the constant numbers defined above, the final status line after 5 turns should be

dog             square       hat              square        Mediterranean Ave.    Baltic Ave.        Reading Railroad

$1561         1                 $1519        3                  1                                     1                        2

If the number of turns is changed to 10, the final status should be

dog             square       hat              square        Mediterranean Ave.    Baltic Ave.        Reading Railroad

$1746        2                 $1734        2                  1                                     1                        2

If player1 move is 3, player2 move is 1 and number of turns is 15, the final status should be

dog

$1948

square

1

hat

$1932

square

3

Mediterranean Ave. 2

Baltic Ave.

1

Reading Railroad

1

Extra Credit (+5)

Replace all the player and property variables with player and property lists. Make each player a list with three items, and each property a list with five items, and do all operations on the list items rather than separate      variables.


Use the template, declare all variables, use good variable names, comments, and generally good style.


Special Notes:

1.   Do not use functions, exceptions, dictionaries, or any other features from chapters beyond Chapter 4,

even if you know how to use them. The purpose of this examination is to test your skills with the topics we have covered in this class; later exercises will assess your skills with the post-chapter 4 topics.           Using more advanced features demonstrates that you don’t know the simpler tools well enough, which will lower your score.

2.   You may use lists, since we did have a limited discussion about them when learning for-in loops.  You may also use the upper() and lower() string methods that we borrowed from chapter 8.

3.   The code you submit must be your own .  The examination is open book and open notes, so you may use any resources, including the Internet, that are not other people’s code.

4.   Code that is identical to another person’s code (ignoring changes in spacing or other trivial                    adjustments) is considered evidence of cheating and all identical code submissions receive a score of

0 on the examination.

5.   If you use code from the Internet, and another student does as well, it could result in parts of your submissions being identical.  It’s not my job to understand how that happened. Please use Internet examples to inform your code, but do not copy it exactly.

The Python program is scored with a maximum value of 100 points.