-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha05_is_even.py
executable file
·51 lines (41 loc) · 1.56 KB
/
a05_is_even.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
######################################################################
# Author: Emily Lovell & Scott Heggen TODO: Change this to your names
# Username: lovelle & heggens TODO: Change this to your usernames
#
# Assignment: A05: The Game of Nim
#
# Purpose: This program is designed to demonstrate the use of Boolean functions
# and the modulus (%) operator which gives the remainder following a division
#
######################################################################
# Acknowledgements:
# Original Author: Dr. Jan Pearce
#
# licensed under a Creative Commons
# Attribution-Noncommercial-Share Alike 3.0 United States License.
####################################################################################
import random
def is_even(num):
"""
Boolean function takes an integer as input. Returns True if even and False if odd
:param num: An integer
:return: Boolean representing if the number is even (True) or odd (False)
"""
return int(num) % 2 == 0 # Notice this is different than the last time you saw this function
def main():
"""
This main function is intended to display the capability of the is_even function
:return: None
"""
stop = False
while not stop:
year = random.randint(0, 2015)
print("\nA random year is " + str(year) + ".")
if is_even(year):
print(str(year)+ " is even.")
else:
print(str(year)+ " is odd.")
stop_input = input("Would you like to stop? [Y|N]")
if stop_input == "Y":
stop = not stop
main()