Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python 101 selection challenge: Cuboid volume\surface area
- print("This code will help you work out the surface area, or volume, of a cuboid.\n")
- routine = input("Would you like the surface area or volume of your shape? [Type S or V] ")
- cube = input("Is your shape a cube? [Type Y or N] ")
- side_1 = float(input("How long is your longest side? "))
- if routine == "S":
- if cube == "Y":
- surface_area = side_1 * side_1 * 6
- elif cube =="N":
- side_2 = float(input("Looking at the end of the cuboid, what is the length of sides on the left\\right? "))
- side_3 = float(input("Still looking at the end, how long are the top\\bottom sides? "))
- end_areas = 2 * side_2 * side_3
- left_right_areas = 2 * side_2 * side_1
- top_bottom_areas = 2 * side_3 * side_1
- surface_area = end_areas + left_right_areas + top_bottom_areas
- else:
- surface_area = 0
- print("\nThe surface area is " + str(surface_area))
- elif routine == "V":
- if cube == "Y":
- volume = side_1 ** 3
- else:
- side_2 = float(input("Looking at the end of the cuboid, what is the length of sides on the left\\right? "))
- side_3 = float(input("Still looking at the end, how long are the top\\bottom sides? "))
- volume = side_1 * side_2 * side_3
- print("\nThe volume is " + str(volume) + "\n")
- else:
- print("\nInvalid selection")
Advertisement
Add Comment
Please, Sign In to add comment