-
Notifications
You must be signed in to change notification settings - Fork 14
/
Padre's Functions
69 lines (57 loc) · 2.26 KB
/
Padre's Functions
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#----------------------------------------------------------------------------------
# This function will calculate all the nubers in a Fibonacci series from 0 to input
# Math from the Python Doc Resource Pages
def fib(input):
a, b = 0, 1
while a < input:
print a,
a, b = b, a+b
#----------------------------------------------------------------------------------
#This function will calculate if input is an even or odd number
def oddeven(input):
leftover = input % 2
if leftover == 0:
print input, "is an even number"
else:
print input, "is an odd number"
#----------------------------------------------------------------------------------
# This function will take sanitize input from the user
def sanitize():
clean = 0
while clean == 0:
dirtyinput = raw_input("Please enter a number: ")
if dirtyinput.isdigit():
clean = 1
else:
print "That is not a valid number: "
# This line converts the string into an integer
cleaninput = int(dirtyinput)
#This returns the clean value
return cleaninput
#----------------------------------------------------------------------------------
def main():
# This calls the "sanitize" function to get CLEAN input from the user
calculate = sanitize()
exit = 0
while exit == 0:
print "|=========================================|"
print "|Welcome to Padre's Useless Number Thingy!|"
print "|=========================================|"
print "| 1: Calculate the Fibonacci Series |"
print "| 2: Tell me if the number is odd or even |"
print "| 3: Exit |"
print "|=========================================|"
menu = raw_input("Please make your selection: ")
if menu == "1":
# Pass the clean input to the fibonacci function
fib(calculate)
print ""
elif menu == "2":
# Pass the clean input to the odd/even function
oddeven(calculate)
elif menu == "3":
exit = 1
else:
print "That is not a valid input"
#----------------------------------------------------------------------------------
main()