"""
Examples
"""
x = input("Enter an integer number...") # returns a string
x = int(x) # converts the string to an integer

# Solution1: start by testing if the remainder
# of the division by two is zero
if x % 2 == 0:
    # even number
    print(x, "is even")
else:
    # odd number
    print(x, "is odd")

"""
# Solution2: start by testing if the remainder
# of the division by two is different than zero
if x % 2:
    # odd number
    print(x, "is odd")
else:
    # even number
    print(x, "is even")
"""

"""
Examples
People between 10 and 80 can ride on a roller coaster. Write a piece of code that, for a given integer variable age, outputs OK if the person is admitted and Not admitted otherwise.
"""

"""
# Version with if-else
age = int(input("What is your age..."))

output_message = "Not admitted"  # optional but good practice

if 10 <= age <= 80:
    output_message = "OK"
else:
    output_message = "Not admitted"

print(output_message)
"""

# Version with if-else ternary expression
age = int(input("What is your age..."))
output_message = "OK" if 10 <= age <= 80 else "Not admitted"
print(output_message)

"""
Examples
Given a piece-wise linear function f( ) write a program that takes a floating point number x and computes and outputs f(x)
"""

# Solution with if-else only

x = float(input("Enter a number..."))

if x <= -3:
    f_x = -x - 3

if -3 < x < 0:
    f_x = x + 3

if 0 <= x < 3:
    f_x = -2 * x + 3

if x >= 3:
    f_x = 0.5 * x - 4.5

print(f_x)

# Solution with if-elif-else

x = float(input("Enter a number..."))

if x <= -3:
  f_x = -x - 3
elif -3 < x < 0:
  f_x = x + 3
elif 0 <= x < 3:
  f_x = -2 * x + 3
else:
  f_x = 0.5 * x - 4.5

print(f_x)