-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparity.py
More file actions
54 lines (41 loc) · 1.14 KB
/
Copy pathparity.py
File metadata and controls
54 lines (41 loc) · 1.14 KB
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
52
53
54
## Using the modular '%' where if the integer has a remainder of a specified number, in this case 2
## Implementig if a number is even or odd
## Or can a number be divided by 2 without remainders, which will determine if a number is even
# x = int(input("What's x? "))
# if x % 2 == 0:
# print("Even")
# else:
# print("Odd")
# ## Another approach, using boolean, 'bool' (True or False)
# def main():
# x = int(input("What's x? "))
# if is_even(x):
# print("Even")
# else:
# print("Odd")
# def is_even(n):
# if n % 2 == 0:
# return True
# else:
# return False
# main()
# ## Pythonic syntax, where the code above can be simplified more
# def main():
# x = int(input("What's x? "))
# if is_even(x):
# print("Even")
# else:
# print("Odd")
# def is_even(n):
# return True if n % 2 == 0 else False
# main()
## Even more simplified from the above:
def main():
x = int(input("What's x? "))
if is_even(x):
print("Even")
else:
print("Odd")
def is_even(n):
return n % 2 == 0 # Note that this is your boolean expression
main()