Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Lighthouse Brick Calculator
- ##Defining Pi
- pi = 3.14159
- ##Mainline Function
- def LighthouseCalc():
- height, df, dt = LHDimensions(pi)
- bricklength, brickheight, brickdepth = BrickType()
- totalbricks = CalcBricks(pi, bricklength, brickheight, brickdepth, height, df, dt)
- print(totalbricks)
- ##Entering lighthouse dimensions (capped at 999 for realism)
- def LHDimensions(pi):
- validheight = False
- validdf = False
- validdt = False
- while validheight == False:
- height = float(input("Enter the desired height of the lighthouse (in metres): "))
- if height <= 0 or height >= 1000:
- print("Enter a valid height.")
- else:
- validheight = True
- while validdf == False:
- df = float(input("Enter the desired diameter of the bottom of the lighthouse (in metres): "))
- if df <= 0.8 or df >= 1000:
- print("Enter a valid diameter for the base.")
- else:
- validdf = True
- while validdt == False:
- dt = float(input("Enter the desired diameter of the top of the lighthouse (in metres): "))
- if dt <= 0.8 or dt >= df:
- print("Enter a valid diameter for the top.")
- else:
- validdt = True
- return height, df, dt
- ##Entering the brick type (values in metres for consistency with calculations)
- def BrickType():
- brickvalid = False
- bricklength = 0
- brickheight = 0
- brickdepth = 0
- while brickvalid == False:
- bricktype = input("Choose the desired brick type (Budget, Superior or Luxury): ")
- if bricktype == "Budget" or bricktype == "budget":
- bricklength = 0.5
- brickheight = 0.35
- brickdepth = 0.3
- brickvalid = True
- elif bricktype == "Superior" or bricktype == "superior":
- bricklength = 0.4
- brickheight = 0.3
- brickdepth = 0.35
- brickvalid = True
- elif bricktype == "Luxury" or bricktype == "luxury":
- bricklength = 0.3
- brickheight = 0.25
- brickdepth = 0.4
- brickvalid = True
- else:
- print("Enter one of the possible brick types.")
- return bricklength, brickheight, brickdepth
- ##Calculating the number of bricks needed
- def CalcBricks(pi, bricklength, brickheight, brickdepth, height, df, dt):
- ##Calculating the dimensions of the inside of the lighthouse
- diabase = df - (2 * brickdepth)
- diatop = dt - (2 * brickdepth)
- ##Using a mathematical formula to calculate the height of the smaller cone
- ##at the top of the lighthouse which is cut off
- coneheight = (diatop * height) / (diabase - diatop)
- ##Calculating the ratio of "external base : height of the uncut cone"
- diaratio = df / (height + coneheight)
- ##Calculating the number of bricks for each ring using the ratio
- heightcount = 0
- totalbricks = 0
- ##The while loop uses "< height + brickheight" so that it can round up to
- ##an integer number of bricks needed if the top ring extends taller than
- ##the specified height of the lighthouse
- while heightcount < height + brickheight:
- layerdia = (height + coneheight - heightcount) * diaratio
- ##The double // and + 1 are used to round up the number of bricks
- ##per layer to an integer
- brickslayer = layerdia * pi // bricklength + 1
- totalbricks = totalbricks + brickslayer
- heightcount = heightcount + brickheight
- ##Calculating the bricks of the door (rounding the door bricks down as
- ##you can cut the bricks that remain to fit the door dimensions exactly)
- doorheight = 2
- doorwidth = 0.9
- doorbricksheight = doorheight // brickheight
- doorbrickswidth = doorwidth // bricklength
- doorbricks = doorbricksheight * doorbrickswidth
- ##Subtracting door bricks from total bricks to get the final total
- totalbricks = totalbricks - doorbricks
- return totalbricks
- ##Calling main function
- LighthouseCalc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement