Created
August 22, 2015 04:25
-
-
Save harfordt/e26dce50ffa5d1514916 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# do calculations inside he try/catch | |
while True: | |
try: | |
length=int(input("\nPlease enter the vertical length of the square (in centimetres): ")) | |
if length<=0 or length>150: | |
print("Please enter a number between 1-150.") | |
continue | |
p_square=length*4 | |
a_square=length*length | |
print("\nThe perimeter of your square is {} centimetres.".format(p_square)) | |
print("\nThe area of your square is {}.".format (a_square)) | |
break | |
except ValueError: | |
print("Please enter integers only.") | |
# use the try/catch *only* to take the input, do calculations once you have a valid value | |
while True: | |
try: | |
length=int(input("\nPlease enter the vertical length of the square (in centimetres): ")) | |
if length<=0 or length>150: | |
print("Please enter a number between 1-150.") | |
continue | |
break | |
except ValueError: | |
print("Please enter integers only.") | |
p_square=length*4 | |
a_square=length*length | |
print("\nThe perimeter of your square is {} centimetres.".format(p_square)) | |
print("\nThe area of your square is {}.".format (a_square)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment