-
Notifications
You must be signed in to change notification settings - Fork 19
/
PDR_note_week1.py
80 lines (57 loc) · 1.56 KB
/
PDR_note_week1.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
75
76
77
78
79
"""
Python Data Representatives
WEEK ONE
Course Note and Quiz
"""
name1 = "Pierre"
age1 = 7
name2 = "May"
age2 = 13
# the use of formatters
line1 = "{0:^7} {1:>3}".format(name1, age1)
line2 = "{0:^7} {1:>3}".format(name2, age2)
print(line1)
print(line2)
num = 3.283663293
output = "{0:>10.3f} {0:.2f}".format(num)
print(output)
# the demonstration of string slices
name = "𝙲𝚊𝚜𝚝𝚕𝚎 𝙰𝚗𝚝𝚑𝚛𝚊𝚡"
print(name[7:])
print(name[7:13])
# the function that required by the by the week one quiz in Python Data RePresentatives
def count_vowels(word):
"""
This function takes a string
returns the number of vowels in that string
"""
vowels = 0
for count in word:
if 'a' == count or 'e' == count or 'i' == count or 'o' == count or 'u' == count:
vowels += 1
return vowels
# the function that required by the by the week one quiz in Python Data RePresentatives
def demystify(l1_string):
"""
This function takes one string that only contains l or 1
replace a with l and b with 1
returns the new string
"""
list_string = list(l1_string)
for idx, char in enumerate(list_string):
if char == 'l':
list_string[idx] = 'a'
elif char == '1':
list_string[idx] = 'b'
else:
pass
return "".join(list_string)
print(count_vowels("aaassseefffgggiiijjjoOOkkkuuuu"))
print(count_vowels("aovvouOucvicIIOveeOIclOeuvvauouuvciOIsle"))
print(demystify("lll111l1l1l1111lll"))
print(demystify("111l1l11l11lll1lll1lll11111ll11l1ll1l111"))
word = "shrubbery"
print(word[-1])
print(word[len(word) - 1])
print(word[0])
# print(word[len(word)]