Skip to content

Instantly share code, notes, and snippets.

@mreed4
Created February 13, 2021 04:37
Show Gist options
  • Save mreed4/d79769ac82780a941131d72640949473 to your computer and use it in GitHub Desktop.
Save mreed4/d79769ac82780a941131d72640949473 to your computer and use it in GitHub Desktop.
Exercise 2 from PracticePython.org
# http://www.practicepython.org/exercise/2014/02/05/02-odd-or-even.html
# Ask the user for a number. Depending on whether the number is even or odd, print out an appropriate message to the
# user. Hint: how does an even-odd number react differently when divided by 2?
# Note to self: This required you looking at the solution
# Greet user
print("\nGreetings, user.")
# User input
def func_get_numbers():
# Get numbers
get_number1 = int(input("\nPlease enter a number: "))
num = get_number1
get_number2 = int(input("Please enter another number, smaller than the first number: "))
check = get_number2
mod = num % 2
# Ensure user plays by the rules
if check > num:
print(f"\n{check} is larger than {num}. Try again!")
func_get_numbers()
else:
# Display chosen numbers
print(f"\nYour numbers are {num} and {check}")
# Check if 'num' is odd or even
if mod > 0:
print(f"\n{num} is an odd number.")
else:
print(f"\n{num} is an even number.")
# Check if 'num' is a multiple of four
if num % 4 == 0:
print(f"{num} is a multiple of 4.")
else:
print(f"{num} is not a multiple of four.")
# Are the numbers divisible?
if num % check == 0:
print(f"{num} divides evenly by {check}! ({num} / {check} = {num/check})")
else:
print(f"{num} is not divisible by {check}. ({num} / {check} = {num/check})")
func_get_numbers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment