-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.py
More file actions
74 lines (69 loc) · 1.85 KB
/
Copy patherrors.py
File metadata and controls
74 lines (69 loc) · 1.85 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
64
65
66
67
68
69
70
71
72
73
74
# 1. Oprava kodu
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
# print('My favorite season is', seasons[4])
print('My favorite season is', seasons[3])
print('My favorite season is', seasons[len(seasons) - 1])
# 2. Oprava kodu
message = 'The rythm of waltz is: '
a = ' DA'
b = ' da'
for number in range(10):
# if (Number % 3 ) == 0:
if (number % 3) == 0:
message = message + a
else:
# message = message + 'b'
message = message + b
print(message)
# 3. Dotaz na uzivatelske jmeno
class NumberInUsername(Exception):
pass
class SpacesInUsername(Exception):
pass
class UsernameNotCapitalized(Exception):
pass
user_name = input('Your name? ')
try:
string_list = list(user_name)
space = ' '
numbers_in_name = [i for i, letter in enumerate(string_list) if letter.isdigit()]
if len(numbers_in_name) > 0:
raise NumberInUsername
if space in string_list:
raise SpacesInUsername
if string_list[0].islower():
raise UsernameNotCapitalized
except NumberInUsername:
print(('Username contains numbers'))
except SpacesInUsername:
print('Username contains spaces')
except UsernameNotCapitalized:
print("Username doesn't start with capital letter")
else:
print("Everything's OK")
# 4. Deleni cisel
def divide():
while True:
dividend = input('Enter dividend ')
if dividend.isdigit():
break
while True:
divisor = input('Enter divisor ')
if divisor.isdigit() and int(divisor) == 0:
print("Divisor can't be equal to zero")
if divisor.isdigit() and int(divisor) != 0:
break
return int(dividend) // int(divisor)
print('The result of division is', divide())
# 5. Debugovani
try:
year = int(input('Greetings! What is your year of origin? '))
except ValueError:
print('This is not a year')
else:
if year <= 1900:
print("Woah, that's the past!")
elif year > 1900 and year < 2020:
print("That's totally the present!")
else:
print("Far out, that's the future!!")