Skip to content

Instantly share code, notes, and snippets.

@bfmcneill
Created March 27, 2020 02:47
Show Gist options
  • Save bfmcneill/18c41e8d4e2a5f9c60fea1be6dd9ce52 to your computer and use it in GitHub Desktop.
Save bfmcneill/18c41e8d4e2a5f9c60fea1be6dd9ce52 to your computer and use it in GitHub Desktop.
whenever user input != integer, the program will ask again and again
# https://www.facebook.com/groups/pythoncodingprogrammingselfinstructionhub/permalink/1622891821193145/
def question_name():
return input("What is your name? ")
def question_age():
while True:
age_string=input("How old are you buddy? ")
try:
age_integer = int(age_string)
return age_integer
except Exception as err:
print(f"[ERROR] -> {err}\n")
print(f" {age_string} is not a number!")
print(" enter a whole number only")
def print_greeting():
print("Well hello people!\n")
def print_name_message(name):
print(f"such an honor for me to meet ya {name}\n")
def print_final_message(age):
pluralize=""
if age > 1:
pluralize="s"
print(f"well, you still are {age} year{pluralize} old")
def main():
print_greeting()
name = question_name()
print_name_message(name)
age=question_age()
print_final_message(age)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment