scipiguy

Python 101: Selection challenge - Surface area or Volume

Apr 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # Python 101 selection challenge: Cuboid volume\surface area
  2.  
  3. print("This code will help you work out the surface area, or volume, of a cuboid.\n")
  4.  
  5. routine = input("Would you like the surface area or volume of your shape? [Type S or V] ")
  6. cube = input("Is your shape a cube? [Type Y or N] ")
  7.  
  8. side_1 = float(input("How long is your longest side? "))
  9.  
  10. if routine == "S":
  11.     if cube == "Y":
  12.         surface_area = side_1 * side_1 * 6
  13.     elif cube =="N":
  14.         side_2 = float(input("Looking at the end of the cuboid, what is the length of sides on the left\\right? "))
  15.         side_3 = float(input("Still looking at the end, how long are the top\\bottom sides? "))
  16.        
  17.         end_areas = 2 * side_2 * side_3
  18.         left_right_areas = 2 * side_2 * side_1
  19.         top_bottom_areas = 2 * side_3 * side_1
  20.         surface_area = end_areas + left_right_areas + top_bottom_areas
  21.     else:
  22.         surface_area = 0
  23.     print("\nThe surface area is " + str(surface_area))
  24. elif routine == "V":
  25.     if cube == "Y":
  26.         volume = side_1 ** 3
  27.     else:
  28.         side_2 = float(input("Looking at the end of the cuboid, what is the length of sides on the left\\right? "))
  29.         side_3 = float(input("Still looking at the end, how long are the top\\bottom sides? "))
  30.         volume = side_1 * side_2 * side_3        
  31.     print("\nThe volume is " + str(volume) + "\n")
  32. else:
  33.     print("\nInvalid selection")
Advertisement
Add Comment
Please, Sign In to add comment