boncey / Flickr4Java

Java API For Flickr. Fork of FlickrJ
BSD 2-Clause "Simplified" License
176 stars 154 forks source link

Program: Painting a wall #524

Closed Robledog87 closed 3 years ago

Robledog87 commented 3 years ago

Subject of the issue

I am trying to correct my code to correctly display wall area 180 as it prints 180.0 and also the paint needed 0.45000 gal not 0.514286. cant figure out what i element i am missing.

Your environment

Python

Steps to reproduce

(1) Prompt the user to input a wall's height and width. Calculate and output the wall's area (integer).

Enter wall height (feet): 12 Enter wall width (feet): 15 Wall area: 180 square feet

(2) Extend to also calculate and output the amount of paint in gallons needed to paint the wall (floating point). Assume a gallon of paint covers 400 square feet. Store this value in a variable. Output the amount of paint needed using the %f conversion specifier.

Enter wall height (feet): 12 Enter wall width (feet): 15 Wall area: 180 square feet Paint needed: 0.450000 gallons

(3) Extend to also calculate and output the number of 1 gallon cans needed to paint the wall. Hint: Use a math function to round up to the nearest gallon.

Enter wall height (feet): 12 Enter wall width (feet): 15 Wall area: 180 square feet Paint needed: 0.450000 gallons Cans needed: 1 can(s)

(4) Extend by prompting the user for a color they want to paint the walls. Calculate and output the total cost of the paint cans depending on which color is chosen. Hint: Use a dictionary to associate each paint color with its respective cost. Red paint costs $35 per gallon can, blue paint costs $25 per gallon can, and green paint costs $23 per gallon can. (Submit for 2 points, so 8 points total).

Enter wall height (feet): 12 Enter wall width (feet): 15 Wall area: 180 square feet Paint needed: 0.450000 gallons Cans needed: 1 can(s)

Choose a color to paint the wall: red Cost of purchasing red paint: $35

Expected behaviour

should be able to print wall area , paint needed , and cans needed , cost of red and blue paint.

Actual behaviour

printing incorrect outputs Wall area: 180.0 square feet should be Wall area: 180 square feet Paint needed: 0.514286 gallons should be Paint needed: 0.450000 gallons Cost of purchasing red paint: $ {'red': 35, 'blue': 75} should be Cost of purchasing red paint: $35

Log my code

import math
# Dictionary of paint colors and cost per gallon
paintColors = {
'red': 35,
'blue': 25,
'green': 23
}

# FIXME (1): Prompt user to input wall's width
# Calculate and output wall area
wallHeight = float(input('Enter wall height (feet):\n'))
wallwidth = float(input('Enter wall width (feet):\n'))
wallArea = float(wallHeight * wallwidth)
print('Wall area:', wallArea, 'square feet') 

# FIXME (2): Calculate and output the amount of paint in gallons needed to paint the wall
paintNeeded = wallArea / 350
print('Paint needed: %f' % paintNeeded, 'gallons')
cansNeeded = math.ceil(paintNeeded)
print('Cans needed:', cansNeeded,'can(s)n')

# FIXME (3): Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer
paintColor = input()
print('Choose a color to paint the wall:')

# FIXME (4): Calculate and output the total cost of paint can needed depending on color
paintCost = {'red':35, 'blue':75}
print('Cost of purchasing', paintColor, 'paint: $', paintCost)