Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The previous assignment had a simplifying assumption that the amount of money would be limited, such that the builder could not afford more than four

The previous assignment had a simplifying assumption that the amount of money would be limited, such that the builder could not afford more than four houses on any property. This assignment will lift that restriction.

There is nothing really special about building hotels in Monopoly. That purchase is simply equal to the price of five houses, and is built only in the same circumstances that would permit five houses (no other property may have fewer than four).

The inputs to the program will be essentially the same -- the color of a property group and the amount of money to be spent. But the following cases should be addressed:

  • if no building is affordable, display "You cannot afford even one house." instead of building 0 houses everywhere.
  • if one can afford to build 5 houses somewhere, announce that a hotel is being built instead of 5 houses.
  • if one can afford to build more than 5 houses somewhere, only build one hotel and nothing else
  • omit the word 'none' in the output (i..e don't say 'one property has none' or 'none have two')

Comparing Homework 2 to Homework 3

The difference in these programs primariliy appears in the final output statement:

Homework 2 Output Homework 3 Output
two will have one and one will have two two will have one and one will have two
one will have none and two will have one two will have one
three will have one and none will have two three will have one
three will have three and none will have four three will have three
two will have four and one will have five two will have four and one will have a hotel
two will have five and none will have six two will have a hotel
one will have seven and two will have eight three will have a hotel

Hint: The simplest and clearest solutions will use 'else' and 'elif' and will not need 'and' or 'or'. A portion of your grade is based on how clear your code is, and how well it avoids producing contradictory output.

Note: All of these decisions in this chart are entirely based on the results of the previous program, so your code should do the same -- wait until the calculations are complete before deciding how to display the results. Do not make your program unnecessarily complicated by trying to identify the different cases before doing any math.

Also Note: three hotels have the cost of 15 houses, which may require a slight modification to how you displayed numbers in the previous assignment. You may have your program state that they can only afford 15 houses, even if they could afford many more than that. Allowing for all the numbers from 16 to 100 (or 1000) is more cumbersome than interesting at this time.

My Code:

block = input("Which color block will you be building on? ")

money = int(input("How much money do you have to spend? "))

board = {'purple':[2,50], 'light blue':[3,50], 'maroon':[3,150] , 'orange':[3,100],'red':[3,150],'yellow':[3,150],'green':[3,200],'dark blue':[2,200]}

numbers=['none','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve']

block = block.lower().strip()

details = board[block]

prop_total = details[0]

cost = details[1]

print("There are", numbers[prop_total], "properties and each house costs", cost)

print("How many houses are already present on these properties?")

max_houses = money//cost

# No. of houses in prop_less properties

less_houses = max_houses // prop_total

# No. of houses left

rem_houses = max_houses%prop_total

# No. of houses in prop_more properties

more_houses = less_houses+1

# No. of properties having more_houses

prop_more=rem_houses

# No. of properties having less_houses

prop_less = prop_total-prop_more

print("You can build",numbers[max_houses], "house(s) --",numbers[prop_less] , "will have",numbers[less_houses], "and", numbers[prop_more], "will have",numbers[more_houses])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions