Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. ##Lighthouse Brick Calculator
  2.  
  3. ##Defining Pi
  4. pi = 3.14159
  5.  
  6. ##Mainline Function
  7.  
  8. def LighthouseCalc():
  9. height, df, dt = LHDimensions(pi)
  10. bricklength, brickheight, brickdepth = BrickType()
  11. totalbricks = CalcBricks(pi, bricklength, brickheight, brickdepth, height, df, dt)
  12. print(totalbricks)
  13.  
  14. ##Entering lighthouse dimensions (capped at 999 for realism)
  15. def LHDimensions(pi):
  16. validheight = False
  17. validdf = False
  18. validdt = False
  19. while validheight == False:
  20. height = float(input("Enter the desired height of the lighthouse (in metres): "))
  21. if height <= 0 or height >= 1000:
  22. print("Enter a valid height.")
  23. else:
  24. validheight = True
  25. while validdf == False:
  26. df = float(input("Enter the desired diameter of the bottom of the lighthouse (in metres): "))
  27. if df <= 0.8 or df >= 1000:
  28. print("Enter a valid diameter for the base.")
  29. else:
  30. validdf = True
  31. while validdt == False:
  32. dt = float(input("Enter the desired diameter of the top of the lighthouse (in metres): "))
  33. if dt <= 0.8 or dt >= df:
  34. print("Enter a valid diameter for the top.")
  35. else:
  36. validdt = True
  37.  
  38. return height, df, dt
  39.  
  40. ##Entering the brick type (values in metres for consistency with calculations)
  41. def BrickType():
  42. brickvalid = False
  43. bricklength = 0
  44. brickheight = 0
  45. brickdepth = 0
  46. while brickvalid == False:
  47. bricktype = input("Choose the desired brick type (Budget, Superior or Luxury): ")
  48. if bricktype == "Budget" or bricktype == "budget":
  49. bricklength = 0.5
  50. brickheight = 0.35
  51. brickdepth = 0.3
  52. brickvalid = True
  53. elif bricktype == "Superior" or bricktype == "superior":
  54. bricklength = 0.4
  55. brickheight = 0.3
  56. brickdepth = 0.35
  57. brickvalid = True
  58. elif bricktype == "Luxury" or bricktype == "luxury":
  59. bricklength = 0.3
  60. brickheight = 0.25
  61. brickdepth = 0.4
  62. brickvalid = True
  63. else:
  64. print("Enter one of the possible brick types.")
  65.  
  66. return bricklength, brickheight, brickdepth
  67.  
  68. ##Calculating the number of bricks needed
  69. def CalcBricks(pi, bricklength, brickheight, brickdepth, height, df, dt):
  70. ##Calculating the dimensions of the inside of the lighthouse
  71. diabase = df - (2 * brickdepth)
  72. diatop = dt - (2 * brickdepth)
  73. ##Using a mathematical formula to calculate the height of the smaller cone
  74. ##at the top of the lighthouse which is cut off
  75. coneheight = (diatop * height) / (diabase - diatop)
  76. ##Calculating the ratio of "external base : height of the uncut cone"
  77. diaratio = df / (height + coneheight)
  78.  
  79. ##Calculating the number of bricks for each ring using the ratio
  80. heightcount = 0
  81. totalbricks = 0
  82. ##The while loop uses "< height + brickheight" so that it can round up to
  83. ##an integer number of bricks needed if the top ring extends taller than
  84. ##the specified height of the lighthouse
  85. while heightcount < height + brickheight:
  86. layerdia = (height + coneheight - heightcount) * diaratio
  87. ##The double // and + 1 are used to round up the number of bricks
  88. ##per layer to an integer
  89. brickslayer = layerdia * pi // bricklength + 1
  90. totalbricks = totalbricks + brickslayer
  91. heightcount = heightcount + brickheight
  92.  
  93. ##Calculating the bricks of the door (rounding the door bricks down as
  94. ##you can cut the bricks that remain to fit the door dimensions exactly)
  95. doorheight = 2
  96. doorwidth = 0.9
  97. doorbricksheight = doorheight // brickheight
  98. doorbrickswidth = doorwidth // bricklength
  99. doorbricks = doorbricksheight * doorbrickswidth
  100. ##Subtracting door bricks from total bricks to get the final total
  101. totalbricks = totalbricks - doorbricks
  102.  
  103. return totalbricks
  104.  
  105.  
  106. ##Calling main function
  107. LighthouseCalc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement