Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3) (15 pts) Using if statement(s), write a script to calculate the volume of a p

ID: 670262 • Letter: 3

Question

3) (15 pts) Using if statement(s), write a script to calculate the volume of a pyramid which is (1/3) *base *height, where the base is length * width. The volume should be outputted in cubic inches. Prompt the user to enter values for the length, width and the height and then calculate the volume of the pyramid. When the user enters each value, he or she should be prompted also for either i for inches, or c for centimeters. Remember i or c is char type and you can add a second argument to the input function to make it clear (e.g., input('Enter a character: ', 's')). As an example, the output might look like this: This program will calculate the volume of a pyramid. Enter the length of the base: 50 Is that in inches or centimeters?: i Enter the width of the base: 6 Is that in inches or centimeters?: c Enter the height: 4 Is that in inches or centimeters?: i The volue of the pyramid in cubic inche The volume of the pyramid in cubic inches 1s:

Explanation / Answer


lengthB=input("enter the length of the base: ")
m=input("Is that inches or centimeter(i/c): ",'c')
if m=='i'
  
else
lengthB=0.394*lengthB
end

widthB=input("enter the width of the base: ")
m=input("Is that inches or centimeter(i/c): ",'c')
if m=='i'
  
else
widthB=0.394*widthB
end
height=input("enter the height: ")
m=input("Is that inches or centimeter(i/c): ",'c')
if m=='i'
  
else
height=0.394*height
end

base=lengthB*widthB
volume=(base*height)/3
fprintf("Volume of pyramid: %f cubic-inches ",volume)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote