-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidation.py
74 lines (65 loc) · 1.7 KB
/
validation.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def number_in(n, arr):
"""Validates input is a number and checks for presence in an array"""
try:
int(n)
except:
print('Only numbers are accepted')
return False
if int(n) in arr:
return True
else:
print(f"Selection must be one of the following:")
for number in arr:
print(f"{number}")
return False
def number_between(n, a, b):
"""Validates input is a number and checks it falls within the two numbers supplied as a and b"""
try:
int(n)
except:
print('Only numbers are accepted')
return False
if int(n) >= a and int(n) <= b:
return True
else:
print(f"Selection must be between {a} and {b}")
return False
def element_in(element, arr):
"""Validates element presence in given array"""
if (element) in arr:
return True
else:
print("Not a valid option, try again")
return False
def is_all_letters(str, arr):
"""Validates string character presence given array"""
for letter in str:
if letter in arr:
continue
else:
print(f"{letter} is not a letter")
return False
return True
def auto_valid(a):
"""Bypass validation step"""
return a == a
def is_odd(num1):
"""Validates number is odd"""
try:
int(num1)
except:
print('Only enter numbers')
return False
if int(num1) % 2 != 0:
return True
else:
print(f'Number must be an odd number')
return False
def is_number(num):
"""Validates iput it a number"""
try:
int(num)
except:
print('Only enter numbers')
return False
return True