-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practice_1.py
163 lines (148 loc) · 3.91 KB
/
Practice_1.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"Exercise: 1 (pag 11)"
'Exercise: 1 (pag 11)'
1256983%28
7
"Seven coins will remain to him"
'Seven coins will remain to him'
"Exercise: 2 (pag 16)"
'Exercise: 2 (pag 16)'
12**25%15
12
8 or 3**5 > 100
8
12<8
False
"First question is False"
'First question is False'
5*3**3
135
900/75
12.0
135 != 12
True
"Second question is True"
'Second question is True'
"Exercise: 3 (pag 21)"
'Exercise: 3 (pag 21)'
"[[]] + "PYTHON"
SyntaxError: unterminated string literal (detected at line 1)
"[[]]" + "PYTHON"
'[[]]PYTHON'
"[[]]"[0:2]+"PYTHON"+"[[]]"[2:4]
'[[PYTHON]]'
"Python"[-2]
'o'
"Python"[0:-2]*4
'PythPythPythPyth'
"Python"[-1:-2]
''
"Python"[4:]
'on'
"Python"[-2:]*4
'onononon'
"Perl"[2]*6
'rrrrrr'
"Exercise: 4 (pag 26)"
'Exercise: 4 (pag 26)'
len ("python")
# => 6
"Exercise: 4 (pag 24)"
'Exercise: 4 (pag 24)'
"python"upper(pyt)
# => SyntaxError: invalid syntax
# => "python".upper(pyt)
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
"python".upper(pyt)
NameError: name 'pyt' is not defined
"python".upper("pyt")
Traceback (most recent call last):
File "<pyshell#28>", line 1, in <module>
"python".upper("pyt")
TypeError: str.upper() takes no arguments (1 given)
"python".upper([0:3])
SyntaxError: invalid syntax
"python".upper('pyt')
Traceback (most recent call last):
File "<pyshell#30>", line 1, in <module>
"python".upper('pyt')
TypeError: str.upper() takes no arguments (1 given)
"python"[0:3].upper()+"python"[-3:0]
'PYT'
"python"[0:3].upper()+"python"[-3:]
'PYThon'
3*"python"[:1]
'ppp'
len("python")*"python"[:1]
'pppppp'
len("git")*"git"[:1]
'ggg'
"Exercise: 5 (pag27)"
'Exercise: 5 (pag27)'
print(7+3*2)
13
print('7'+str(3*2))
76
print('7'+'3*2')
73*2
print('7'+3*2)
Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
print('7'+3*2)
TypeError: can only concatenate str (not "int") to str
print((7+3)*2)
20
"The error is causing because the semantics of the numbers in every case"
'The error is causing because the semantics of the numbers in every case'
"Exercise: 6 (pag31)"
'Exercise: 6 (pag31)'
your hobby="basketball"
SyntaxError: invalid syntax
your_hobby="basketball"
'My hobby is {0}.'.format{your_hobby}
SyntaxError: invalid syntax
'My hobby is {0}.'.format(your_hobby)
'My hobby is basketball.'
f'My hobby is {your_hobby}.
SyntaxError: unterminated string literal (detected at line 1)
date='2018-11-01'
date
'2018-11-01'
date='01/11'
date
'01/11'
"Exercise: 7 (37)"
'Exercise: 7 (37)'
the favourite one will be the first=['Read books']
SyntaxError: invalid syntax
the_favourite_one_will_be_the_first=['Read books']
the_favourite_one_will_be_the_first.append('Hiking')
the_favourite_one_will_be_the_first.append('Theater')
the_favourite_one_will_be_the_first.append('Puzzles')
the_favourite_one_will_be_the_first.append('Clarinet')
the_favourite_one_will_be_the_first.append('Bastketball')
the_favourite_one_will_be_the_first.append('Writing')
the_favourite_one_will_be_the_first.append('Dancing')
the_favourite_one_will_be_the_first
['Read books', 'Hiking', 'Theater', 'Puzzles', 'Clarinet', 'Bastketball', 'Writing', 'Dancing']
the_favourite_one_will_be_the_first[0]
'Read books'
the_favourite_one_will_be_the_first[4]
'Clarinet'
the_favourite_one_will_be_the_first.del[4]
SyntaxError: invalid syntax
del the_favourite_one_will_be_the_first[4]
the_favourite_one_will_be_the_first
['Read books', 'Hiking', 'Theater', 'Puzzles', 'Bastketball', 'Writing', 'Dancing']
"Exercise: 8 (38)"
'Exercise: 8 (38)'
cities = ['Prague', 'Brno', 'Ostrava', 'Plzen', 'Liberec', 'Olomouc', 'Usti nad Labem', 'Hradec Kralove', 'Ceske Budejovice', 'Pardubice']
cities.sort()
cities
['Brno', 'Ceske Budejovice', 'Hradec Kralove', 'Liberec', 'Olomouc', 'Ostrava', 'Pardubice', 'Plzen', 'Prague', 'Usti nad Labem']
"*".join(cities)
'Brno*Ceske Budejovice*Hradec Kralove*Liberec*Olomouc*Ostrava*Pardubice*Plzen*Prague*Usti nad Labem'
"Excercise: 9 (pag49)"
'Excercise: 9 (pag49)'
print output
import subprocess