Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
A simple Even or Odd Dectector
Functions of this program:
- Recieve input from the user
- Determine the range of detection from user input
- Outputs the various numbers together with their results (even or odd)
#Generates range and checks if the number leaves a remainder
for x in range(first_number, second_number):
if x % 2 == 0:
print(x, " is an even number")
elif x % 2 != 0:
print(x, " is an odd number")
def even_odd():
print("This program tells whether each number in a given range is even or odd")
first_number = int(input("Enter first number in the range"))
second_number = int(input("Enter final number in range"))
for x in range(first_number, second_number):
if x % 2 == 0:
print(x, " is an even number")
elif x % 2 != 0:
print(x, " is an odd number")
even_odd()
exit_ans = input()
while True:
if exit_ans == 'y' or 'yes':
even_odd()
elif exit_ans != 'y':
exit()
This is a function which takes in a numerator and a denominator. It's a simple division calculation tool which gives you your answer in decimals, gives a floor division answer and the remainder of the division.
def remainder():
print("This program is an advanced division calculator")
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
c = 0
if a % b == 0 :
c = a / b
print("Your answer is ", float(c))
print("And leaves no remainder")
elif a % b != 0:
c = a / b
print("Your decimal answer is ", float(c))
c = a//b
print("Your floor answer is ", c)
c = a%b
print("And leaves a remainder of ",c)
remainder()
exit_ans = input("Do you want to exit [y/n]")
while True:
if exit_ans == 'n':
remainder()
else:
exit()
my_age = 14
my_fake_age = 16
average_age = 15