Created
March 9, 2021 15:54
-
-
Save BlairCurrey/d7b2e3f87610703b2f34af36579e2c3a 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
# This command-line test gets an input from the user and | |
# attempts to square it. If there are no issues it | |
# prints the result of squaring the input. If the input | |
# is not an integer a ValueError is raised which triggers | |
# the 'except' which prints the issue to the user. If another | |
# exception occurs it will not be caught and will terminate the | |
# program and print the error message to the console. | |
while True: | |
val = input("Enter a number to square: ") | |
try: | |
squared = int(val) ** 2 | |
print("You number squared: ", squared) | |
except ValueError: | |
print("Number must be an integer.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment