Question

Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width,...

Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width, and height of the box) and returns the volume of the box. Then, use that function in a program which prompts the user to enter the dimensions of a box and returns the volume. Your program should include input validation to ensure that the values entered are positive and should be able to accept float values.

Many thanks for all your time and effort in helping me with the above question.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def volume_of_box(length, width, height):
    return length * width * height


def main():
    while True:
        try:
            length = float(input("Enter length: "))
            if length > 0:
                break
            print("Invalid input. Try again!")
        except ValueError:
            print("Invalid input. Try again!")
    while True:
        try:
            width = float(input("Enter width: "))
            if width > 0:
                break
            print("Invalid input. Try again!")
        except ValueError:
            print("Invalid input. Try again!")
    while True:
        try:
            height = float(input("Enter height: "))
            if height > 0:
                break
            print("Invalid input. Try again!")
        except ValueError:
            print("Invalid input. Try again!")
    print("Volume of the box is " + str(volume_of_box(length, width, height)))


if __name__ == '__main__':
    main()

Add a comment
Know the answer?
Add Answer to:
Use Python 3.7 to Write a function called volume_of_box() that takes three parameters (the length, width,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT