-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors_demo.py
More file actions
63 lines (55 loc) · 1.51 KB
/
Copy patherrors_demo.py
File metadata and controls
63 lines (55 loc) · 1.51 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
55
56
57
58
59
60
61
62
63
list = ["1", "2", "5a", "10b", "abc"]
list2 = []
# Find numeric data in list
for i in list:
try:
result = int(i)
except Exception:
continue
else:
list2.append(result)
print(list2)
# Check user enter numeric numbers all the time except enter 'q' unless throw exception
while True:
result = input("Please enter a number. If you want to exit please press 'q' = ")
try:
int(result)
print("It is a number")
except ValueError as e:
if result == 'q':
print("Have a good day!")
break
else:
print("Please enter a number")
# Check the password is not include Turkish letter.
def check_password(psw):
import re
if re.search("[ı,İ,ğ,Ğ,ü,Ü,ş,Ş,ö,Ö,ç,Ç]", psw):
raise Exception("Password can not include Turkish case!")
while True:
password = input("Please enter a password: ")
try:
check_password(password)
except Exception as e:
print(e)
else:
print("Password is valid.")
break
# Create factorial function and throw error message for incoming value from function.
def fac(x):
if x == 1:
return x
elif x < 0:
raise Exception("You can not enter negative number.")
else:
return x * fac(x - 1)
while True:
try:
result = int(input("Enter a number ="))
print(fac(result))
except ValueError as a:
print("You can not enter letter.")
except Exception as a:
print(a)
else:
break