# Volume / Surface Area Calculator, GTT, 2016 # **** Functions go here ***** def num_check(question): valid = False while not valid: try: response = float(input(question)) if response > 0: return response else: print("Please input a number that is more than zero") except ValueError: print("Please enter a number") # **** Main Routine goes here **** keep_going = "" while keep_going == "": length = num_check("Length in cm: ") width = num_check("Width in cm: ") height = num_check("Height in cm: ") volume = length * width * height surface_area = 2 * (length * width) + 2 * (length * height) + 2 * (width * height) print() print("*** Answers Below ****") print("Volume: {} cm^3".format(volume)) print("Surface Area: {} cm^2".format(surface_area)) print() keep_going = input("Press <enter> to solve another problem or any key to quit") print()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question