Last active
March 7, 2020 20:07
-
-
Save JackKell/a5d09556d560f7df60b378d02872755d 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
# getting an integer | |
def getIntegerInput(prompt: str, lowerBound: int = None, upperBound: int = None) -> int: | |
while True: | |
userInput = input(prompt) | |
try: | |
userInput = int(userInput) | |
if lowerBound and userInput < lowerBound: | |
print(f"Input must be greater than or equal to {str(lowerBound)}") | |
elif upperBound and userInput > upperBound: | |
print(f"Input must be less than or equal to {str(upperBound)}") | |
except ValueError: | |
print(f"{userInput}: is not a valid integer") | |
continue | |
return userInput | |
# Example usages | |
Day = getIntegerInput("Enter the day which you were born in: ", 1, 31) | |
Month = getIntegerInput("Enter the number of the month you were born in: ", 1, 12) | |
Year = getIntegerInput("Enter the year you were born in: ", 1950) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment