This repository has been archived by the owner on Aug 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW11.py
70 lines (58 loc) · 1.51 KB
/
HW11.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
"""
Homework Assignment #11: Error Handling
From assignment 3: "If" Statements
"""
# compare three values, return true only if 2 or more values are equal
# integer value of boolean True is 1
# integer value of boolean False is 0
def compare(a = None, b = None, c = None):
try:
value = False
a = int(a)
b = int(b)
c = int(c)
print("Valid values.")
if a == b or a == c or b == c:
value = True
except ValueError:
print("ValueError: Only, numbers are allowed.")
except TypeError:
print("TypeError: Please enter only numbers.")
except Exception:
print(Exception)
print("Exception, Only numbers are allowed!")
finally:
print("Values ", a, b, c)
return value
# all integers
print("Result: ",compare(1, 2, 3))
print("\n")
# numbers in str
print("Result: ",compare("2", "3", "4"))
print("\n")
# alphabets
print("Result: ",compare("a", "b", "c"))
print("\n")
# one boolean
print("Result: ",compare(True))
print("\n")
# three boolean values
print("Result: ",compare(True, True, False))
print("\n")
# integer with list
print("Result: ",compare(1, 2, [True]))
print("\n")
# str with boolean
print("Result: ",compare("2", "2", True))
print("\n")
# equal numbers in str
print("Result: ",compare("2", "2", "2"))
print("\n")
# empty str
print("Result: ",compare("-1", ""))
print("\n")
# three empty str
print("Result: ",compare("", "", ""))
print("\n")
#floats
print("Result: ",compare("1.1", "1","1.1"))