I’ve always played a version of Monopoly that provided the players with an in-game credit card, which could be used in transactions made on a card reader, which was also provided. I was disappointed to see that the new copy that I bought only had paper money. Because of this, I made the decision to recreate the bank system used in my old Monopoly on Python. You can the link to this project on Github here.
import pprint
accounts = {"a":1500, "b":1500, "c":1500}
while 1:
print("Welcome to Monopoly Calculator")
opp = input("What would you like to do?: ")
player = opp[0]
operation = opp[1]
amount = int(opp[2:])
if operation == "-":
amount *= -1
accounts[player] = accounts[player] + amount
pprint.pprint(accounts)
print("Thank you for your transaction\n-*-")
First, a dictionary was used to store the starter value of 1500 for all of the variables – all players usually start with this amount of cash when playing Monopoly. Then, the user’s input is collected into a variable, which contains all the details needed for the operation. Here is an example of an input:
a+1500
In the example above, the first element is one of the three variables, second is the type of transaction that needs to be carried out (deposit or withdrawal), and third, the amount of money that will be used in the transaction.