Testando Funções Do Python No Google Colab
Testando Funções Do Python No Google Colab
Testando Funções Do Python No Google Colab
Hello world
11
Hello
hello world
HELLO WORLD
1
[23]: greeting = 'Hello'
name = 'Augusto'
message = greeting + ', ' + name
print(message)
Hello, Augusto
[28]: print(help(str.lower))
Help on method_descriptor:
lower(self, /)
Return a copy of the string converted to lowercase.
None
[ ]:
2
2
[ ]: #Operadores:
num_1 = '100'
num_2 = '200'
[49]: # Adição:
print(3 + 2)
[32]: # Subtração:
print(3 - 2)
[33]: # Multiplicação:
print(3 * 2)
[34]: # Divisão:
print(3 / 2)
1.5
[36]: # Exponente:
print(3 ** 2)
[37]: # Modulo:
print(3 % 2)
[38]: # Comparações:
# igualdade:
1
print(3 == 2)
False
[39]: #desigualdade:
print(3 != 2)
True
True
False
True
False
[ ]:
[ ]:
2
3
['Physics', 'CompSci']
courses.remove('Math')
1
print(courses)
courses.reverse()
print(courses)
nums.sort(reverse= True)
courses.sort(reverse= True)
print(courses)
print(nums)
sorted_courses = sorted(courses)
print(sorted_courses)
True
2
History
Math
Physics
CompSci
0 History
1 Math
2 Physics
3 CompSci
list_1[0] = 'Art'
print(list_1)
print(list_2)
{'CompSci', 'Physics'}
[ ]:
3
4
print(student['courses'])
['Math', 'CompSci']
print(student.get('name'))
Augusto
print(student.get('phone','not found'))
not found
del student['age']
print(student)
age = student.pop('age')
print(student)
1
[10]: student = {'name': 'Augusto', 'age': 26, 'courses': ['Math', 'CompSci']}
for key, value in student.items():
print(key, value)
name Augusto
age 26
courses ['Math', 'CompSci']
[ ]:
2
5
if language =='Python':
print('Conditional was True')
if language =='Python':
print('Conditional was True')
else:
print('no match')
no match
if language =='Python':
print('Conditional was True')
elif language =='Java':
print('language was java')
else:
print('no match')
if language =='Python':
print('Conditional was True')
elif language =='Java':
print('language was java')
elif language =='Javascript':
print('language was javascript')
else:
print('no match')
1
[9]: user = 'Admin'
logged_in = True
if user == 'Admin' and logged_in:
print('Admin Page')
else:
print('Bad Creds')
Admin Page
Please log in
[12]: a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
True
[13]: a = [1, 2, 3]
b = [1, 2, 3]
print(a is b)
False
[14]: a = [1, 2, 3]
b = a
print(id(a))
print(id(b))
print(a is b)
1773087071744
1773087071744
True
[15]: a = [1, 2, 3]
b = a
2
print(id(a))
print(id(b))
print(id(a)==id(b))
1773087063552
1773087063552
True
condition = False
if condition:
print('Evaluated to True')
else:
print('Evaluated to False')
Evaluated to False
[ ]:
3
6
1
2
Found!
1
2
Found!
4
5
1 a
1 b
1 c
2 a
2 b
2 c
3 a
1
3 b
3 c
4 a
4 b
4 c
5 a
5 b
5 c
1
2
3
4
5
6
7
8
9
10
[10]: x = 0
while x < 10:
print(x)
x += 1
0
1
2
3
4
5
6
7
8
9
[11]: x = 0
while x < 10:
if x==5:
break
print(x)
x += 1
0
1
2
2
3
4
[ ]:
3
7
hello function!
hello function!
hello function!
hello function!
hello function!
print(hello_func().upper())
HELLO FUNCTION!
print(hello_func('Hi'))
Hi Function.
1
print(hello_func('Hi'))
Hi, You
print(hello_func('Hi', name='Augusto'))
Hi, Augusto
('Math', 'Art')
{'name': 'Augusto', 'age': 26}
courses = ['Math','Art']
info = {'name':'Augusto','age':22}
student_info(*courses, **info)
('Math', 'Art')
{'name': 'Augusto', 'age': 22}
def is_leap(year):
"""Return True for leap years, False for non-leap years."""
2
return month_days[month]
print(is_leap(2021))
False
def is_leap(year):
"""Return True for leap years, False for non-leap years."""
return month_days[month]
print(days_in_month(2021,2))
28
[ ]:
3
9
[1]: import os
os.chdir('/Users/augus/Desktop/')
print(os.getcwd())
C:\Users\augus\Desktop
[2]: import os
os.chdir('/Users/augus/Desktop/')
print(os.listdir())
[6]: import os
os.chdir('/Users/augus/Desktop/')
#os.mkdir('OS-Demo-2/Sub-Dir-1')
os.makedirs('OS-Demo-2/Sub-Dir-1')
print(os.listdir())
1
'Entrevistas com clientes sobre os produtos desenvolvidos do aplicativo
Vitta.docx', 'It Takes Two.lnk', 'memorial do sistema desenvolvido do aplicativo
Vitta.pdf', 'memorial do sistema desenvolvido.docx', 'OS-Demo-2', 'Primeira
versão no figma.docx', 'Primeira versão no figma.pdf', 'Projeto Eletrônico -
Augusto Pereira Salgado 11311ECP016.docx', 'Projeto Eletrônico - Augusto Pereira
Salgado 11311ECP016.pdf', 'Proposta de aplicativo Augusto Pereira Salgado
11311ECP016.docx', 'Proposta de aplicativo Augusto Pereira Salgado
11311ECP016.pdf', 'venv.txt', 'Visual Studio Code.lnk', 'W10 Digital Activation
1.3.9.zip', 'Zelda Ocarina of Time 4K - Atalho.lnk']
[7]: import os
os.chdir('/Users/augus/Desktop/')
os.removedirs('OS-Demo-2/Sub-Dir-1')
print(os.listdir())
[8]: import os
os.chdir('/Users/augus/Desktop/')
os.rename('text.txt','demo.txt')
print(os.listdir())
2
11311ECP016.pdf', 'Proposta de aplicativo Augusto Pereira Salgado
11311ECP016.docx', 'Proposta de aplicativo Augusto Pereira Salgado
11311ECP016.pdf', 'venv.txt', 'Visual Studio Code.lnk', 'W10 Digital Activation
1.3.9.zip', 'Zelda Ocarina of Time 4K - Atalho.lnk']
[13]: import os
os.chdir('/Users/augus/Desktop/')
os.stat('demo.txt')
#print(os.listdir())
[12]: import os
os.chdir('/Users/augus/Desktop/')
print(os.stat('demo.txt').st_size)
#print(os.listdir())
11
[14]: import os
os.chdir('/Users/augus/Desktop/')
print(os.stat('demo.txt').st_mtime)
#print(os.listdir())
1626822014.4637685
[17]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
mod_time = os.stat('demo.txt').st_mtime
print(datetime.fromtimestamp(mod_time))
3
#print(os.listdir())
2021-07-20 20:00:14.463768
[20]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
[29]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.environ.get('HOME'))
None
[30]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.path.dirname('/tmp/test.txt'))
/tmp
4
[31]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.path.split('/tmp/test.txt'))
('/tmp', 'test.txt')
[32]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.path.exists('/tmp/test.txt'))
False
[33]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.path.isfile('/tmp/test.txt'))
False
[34]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(os.path.splitext('/tmp/test.txt'))
('/tmp/test', '.txt')
[35]: import os
from datetime import datetime
os.chdir('/Users/augus/Desktop/')
print(dir(os.path))
5
'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath', 'os', 'pardir',
'pathsep', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'sep',
'split', 'splitdrive', 'splitext', 'stat', 'supports_unicode_filenames', 'sys']
[ ]:
6
10
test.txt
f.close()
True
print(f_contents)
print(f_contents)
1
['1) This is a test file\n', '2) With multiple lines of data…\n', '3) Third
line\n', '4) Fourth line\n', '5) Fifth line\n', '6) Sixth line\n', '7) Seventh
line\n', '8) Eighth line\n', '9) Ninth line\n', '10) Tenth line']
print(f_contents, end='')
f_contents = f.readline()
print(f_contents, end='')
print(f_contents, end='')
print(f_contents, end='')
2
4) Fourth line
5) Fifth line
print(f.tell())
10
3
[18]: with open('test.txt', 'w') as f:
f.write('Test')
print(f_contents)
Test
print(f_contents)
Rest
print(f_contents)
4
11
[1]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
print(f)
1.jpg
2.jpg
3.gif
4.jpg
5.jpg
chá.png
Sem título.jpg
voltar.png
[6]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
print(os.path.splitext(f))
('1', '.jpg')
('2', '.jpg')
('3', '.gif')
('4', '.jpg')
('5', '.jpg')
('chá', '.png')
('Sem título', '.jpg')
('voltar', '.png')
[8]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
file_name, file_ext = os.path.splitext(f)
print(file_name)
1
1
2
3
4
5
chá
Sem título
voltar
[10]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
file_name, file_ext = os.path.splitext(f)
print(file_name.split('-'))
['1']
['2']
['3']
['4']
['5']
['chá']
['Sem título']
['voltar']
[23]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
file_name, file_ext = os.path.splitext(f)
f_title = file_name.split('-')
f_course = file_name.split('-')
f_number = file_name.split('-')
['1']-['1']-['1'].jpg
['2']-['2']-['2'].jpg
['3']-['3']-['3'].gif
['4']-['4']-['4'].jpg
['5']-['5']-['5'].jpg
['chá']-['chá']-['chá'].png
['Sem título']-['Sem título']-['Sem título'].jpg
['voltar']-['voltar']-['voltar'].png
2
[32]: import os
os.chdir('/Users/augus/Desktop/teste/')
for f in os.listdir():
file_name, file_ext = os.path.splitext(f)
f_title = file_name.split('-')
f_course = file_name.split('-')
f_number = file_name.split('-')
#os.rename(fn, new_name)
['1']-['1']-['1'].jpg
['2']-['2']-['2'].jpg
['3']-['3']-['3'].gif
['4']-['4']-['4'].jpg
['5']-['5']-['5'].jpg
['chá']-['chá']-['chá'].png
['Sem título']-['Sem título']-['Sem título'].jpg
['voltar']-['voltar']-['voltar'].png
[ ]:
3
13
1
['Maggie', 'Jefferson', '[email protected]']
['Mary', 'Wilks', '[email protected]']
['Neil', 'Patterson', '[email protected]']
['Corey', 'Davis', '[email protected]']
['Steve', 'Jacobs', '[email protected]']
['Jane', 'Jenkins', '[email protected]']
['John', 'Jacobs', '[email protected]']
['Neil', 'Smith', '[email protected]']
['Corey', 'Wilks', '[email protected]']
['Corey', 'Smith', '[email protected]']
['Mary', 'Patterson', '[email protected]']
['Jane', 'Stuart', '[email protected]']
['Travis', 'Arnold', '[email protected]']
['John', 'Robinson', '[email protected]']
['Travis', 'Arnold', '[email protected]']
next(csv_reader)
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
2
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
['first_name-last_name-email']
['John-Doe-"[email protected]"']
['Mary-"Smith-Robinson"[email protected]']
['[email protected]']
3
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
['[email protected]']
4
for line in csv_reader:
print(line['email'])
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
5
[51]: import csv
csv_writer.writeheader()
OrderedDict([('first_name\tlast_name', 'John\tDoe')])
OrderedDict([('first_name\tlast_name', 'Mary\tSmith-Robinson')])
OrderedDict([('first_name\tlast_name', 'Dave\tSmith')])
OrderedDict([('first_name\tlast_name', 'Jane\tStuart')])
OrderedDict([('first_name\tlast_name', 'Tom\tWright')])
OrderedDict([('first_name\tlast_name', 'Steve\tRobinson')])
OrderedDict([('first_name\tlast_name', 'Nicole\tJacobs')])
OrderedDict([('first_name\tlast_name', 'Jane\tWright')])
OrderedDict([('first_name\tlast_name', 'Jane\tDoe')])
OrderedDict([('first_name\tlast_name', 'Kurt\tWright')])
OrderedDict([('first_name\tlast_name', 'Kurt\tRobinson')])
OrderedDict([('first_name\tlast_name', 'Jane\tJenkins')])
OrderedDict([('first_name\tlast_name', 'Neil\tRobinson')])
OrderedDict([('first_name\tlast_name', 'Tom\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Sam\tJenkins')])
OrderedDict([('first_name\tlast_name', 'Steve\tStuart')])
OrderedDict([('first_name\tlast_name', 'Maggie\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Maggie\tStuart')])
OrderedDict([('first_name\tlast_name', 'Jane\tDoe')])
OrderedDict([('first_name\tlast_name', 'Steve\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Dave\tSmith')])
OrderedDict([('first_name\tlast_name', 'Sam\tWilks')])
OrderedDict([('first_name\tlast_name', 'Kurt\tJefferson')])
6
OrderedDict([('first_name\tlast_name', 'Sam\tStuart')])
OrderedDict([('first_name\tlast_name', 'Jane\tStuart')])
OrderedDict([('first_name\tlast_name', 'Dave\tDavis')])
OrderedDict([('first_name\tlast_name', 'Sam\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Tom\tJefferson')])
OrderedDict([('first_name\tlast_name', 'Jane\tStuart')])
OrderedDict([('first_name\tlast_name', 'Maggie\tJefferson')])
OrderedDict([('first_name\tlast_name', 'Mary\tWilks')])
OrderedDict([('first_name\tlast_name', 'Neil\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Corey\tDavis')])
OrderedDict([('first_name\tlast_name', 'Steve\tJacobs')])
OrderedDict([('first_name\tlast_name', 'Jane\tJenkins')])
OrderedDict([('first_name\tlast_name', 'John\tJacobs')])
OrderedDict([('first_name\tlast_name', 'Neil\tSmith')])
OrderedDict([('first_name\tlast_name', 'Corey\tWilks')])
OrderedDict([('first_name\tlast_name', 'Corey\tSmith')])
OrderedDict([('first_name\tlast_name', 'Mary\tPatterson')])
OrderedDict([('first_name\tlast_name', 'Jane\tStuart')])
OrderedDict([('first_name\tlast_name', 'Travis\tArnold')])
OrderedDict([('first_name\tlast_name', 'John\tRobinson')])
OrderedDict([('first_name\tlast_name', 'Travis\tArnold')])
7
14
print(list(csv_data))
1
'1.00', '2.00', 'Ok', '', '2017-05-26 01:23:14.097393'], ['Maggie', 'Stuart',
'[email protected]', '1.00', '2.00', 'Ok', '', '2017-05-19
23:11:08.624354'], ['Jane', 'Doe', '[email protected]', '1.00', '3.00',
'Ok', '', '2017-04-15 19:40:17.044921'], ['Steve', 'Patterson',
'[email protected]', '1.00', '3.00', 'Ok', '', '2017-04-09
17:14:23.591656'], ['Dave', 'Smith', '[email protected]', '1.00', '3.00',
'Ok', '', '2017-04-01 18:35:10.731005'], ['Sam', 'Wilks',
'[email protected]', '1.00', '4.00', 'Ok', '', '2017-03-01 09:40:56'],
['Kurt', 'Jefferson', '[email protected]', '1.00', '5.00', 'Ok', '',
'2017-02-24 08:23:05'], ['Sam', 'Stuart', '[email protected]', '1.00',
'5.00', 'Ok', '', '2017-02-12 00:14:31'], ['Jane', 'Stuart',
'[email protected]', '1.00', '5.00', 'Ok', '', '2017-02-06 14:52:28'],
['Dave', 'Davis', '[email protected]', '1.00', '0.00', '', '',
'2016-11-18 01:37:25'], ['Sam', 'Patterson', '[email protected]',
'1.00', '8.00', 'Ok', '', '2016-11-01 11:27:17'], ['Tom', 'Jefferson',
'[email protected]', '1.00', '10.00', 'Ok', '', '2016-09-27
09:56:48'], ['Jane', 'Stuart', '[email protected]', '1.00', '7.00', '',
'', '2016-08-09 14:42:25'], ['Maggie', 'Jefferson',
'[email protected]', '1.00', '12.00', 'Ok', '', '2016-07-26
05:02:16'], ['No Reward', 'Description: (None for No Reward)', '', '', '', '',
'', ''], ['Mary', 'Wilks', '[email protected]', '20.00', '60.00', 'Ok',
'', '2017-04-21 02:44:43.395224'], ['Neil', 'Patterson',
'[email protected]', '10.00', '80.00', 'Ok', '', '2016-11-12
17:49:37'], ['Corey', 'Davis', '[email protected]', '6.00', '90.00',
'Ok', '', '2016-04-01 15:19:52'], ['Steve', 'Jacobs',
'[email protected]', '5.00', '21.00', 'Ok', '', '2017-01-04 19:38:44'],
['Jane', 'Jenkins', '[email protected]', '5.00', '30.00', 'Ok', '',
'2017-01-15 17:24:39'], ['John', 'Jacobs', '[email protected]', '3.14',
'34.54', 'Ok', '', '2016-08-23 16:09:25'], ['Neil', 'Smith',
'[email protected]', '3.00', '24.00', 'Ok', '', '2016-11-28 02:57:48'],
['Corey', 'Wilks', '[email protected]', '2.00', '8.00', 'Ok', '',
'2017-03-26 20:13:08.207869'], ['Corey', 'Smith', '[email protected]',
'1.00', '0.00', 'Ok', '', '2017-07-05 01:50:35.171076'], ['Mary', 'Patterson',
'[email protected]', '1.00', '0.00', 'Ok', '', '2017-07-04
18:05:23.052059'], ['Jane', 'Stuart', '[email protected]', '1.00',
'2.00', 'Ok', '', '2017-05-21 19:42:36.098523'], ['Travis', 'Arnold',
'[email protected]', '1.00', '3.00', 'Ok', '', '2017-04-19
08:04:33.428559'], ['John', 'Robinson', '[email protected]', '1.00',
'4.00', 'Ok', '', '2017-03-30 14:59:33.850333'], ['Travis', 'Arnold',
'[email protected]', '1.00', '6.00', 'Ok', '', '2017-01-28 22:02:57']]
2
next(csv_data)
next(csv_data)
for line in csv_data:
print(line)
3
['Sam', 'Wilks', '[email protected]', '1.00', '4.00', 'Ok', '',
'2017-03-01 09:40:56']
['Kurt', 'Jefferson', '[email protected]', '1.00', '5.00', 'Ok', '',
'2017-02-24 08:23:05']
['Sam', 'Stuart', '[email protected]', '1.00', '5.00', 'Ok', '',
'2017-02-12 00:14:31']
['Jane', 'Stuart', '[email protected]', '1.00', '5.00', 'Ok', '',
'2017-02-06 14:52:28']
['Dave', 'Davis', '[email protected]', '1.00', '0.00', '', '',
'2016-11-18 01:37:25']
['Sam', 'Patterson', '[email protected]', '1.00', '8.00', 'Ok', '',
'2016-11-01 11:27:17']
['Tom', 'Jefferson', '[email protected]', '1.00', '10.00', 'Ok', '',
'2016-09-27 09:56:48']
['Jane', 'Stuart', '[email protected]', '1.00', '7.00', '', '',
'2016-08-09 14:42:25']
['Maggie', 'Jefferson', '[email protected]', '1.00', '12.00', 'Ok',
'', '2016-07-26 05:02:16']
['No Reward', 'Description: (None for No Reward)', '', '', '', '', '', '']
['Mary', 'Wilks', '[email protected]', '20.00', '60.00', 'Ok', '',
'2017-04-21 02:44:43.395224']
['Neil', 'Patterson', '[email protected]', '10.00', '80.00', 'Ok',
'', '2016-11-12 17:49:37']
['Corey', 'Davis', '[email protected]', '6.00', '90.00', 'Ok', '',
'2016-04-01 15:19:52']
['Steve', 'Jacobs', '[email protected]', '5.00', '21.00', 'Ok', '',
'2017-01-04 19:38:44']
['Jane', 'Jenkins', '[email protected]', '5.00', '30.00', 'Ok', '',
'2017-01-15 17:24:39']
['John', 'Jacobs', '[email protected]', '3.14', '34.54', 'Ok', '',
'2016-08-23 16:09:25']
['Neil', 'Smith', '[email protected]', '3.00', '24.00', 'Ok', '',
'2016-11-28 02:57:48']
['Corey', 'Wilks', '[email protected]', '2.00', '8.00', 'Ok', '',
'2017-03-26 20:13:08.207869']
['Corey', 'Smith', '[email protected]', '1.00', '0.00', 'Ok', '',
'2017-07-05 01:50:35.171076']
['Mary', 'Patterson', '[email protected]', '1.00', '0.00', 'Ok', '',
'2017-07-04 18:05:23.052059']
['Jane', 'Stuart', '[email protected]', '1.00', '2.00', 'Ok', '',
'2017-05-21 19:42:36.098523']
['Travis', 'Arnold', '[email protected]', '1.00', '3.00', 'Ok', '',
'2017-04-19 08:04:33.428559']
['John', 'Robinson', '[email protected]', '1.00', '4.00', 'Ok', '',
'2017-03-30 14:59:33.850333']
['Travis', 'Arnold', '[email protected]', '1.00', '6.00', 'Ok', '',
'2017-01-28 22:02:57']
4
[6]: import csv
html_output = ''
names = []
next(csv_data)
next(csv_data)
for line in csv_data:
names.append(f"{line[0]} {line[1]}")
John Doe
Dave Smith
Mary Jacobs
Jane Stuart
Tom Wright
Steve Robinson
Nicole Jacobs
Jane Wright
Jane Doe
Kurt Wright
Kurt Robinson
Jane Jenkins
Neil Robinson
Tom Patterson
Sam Jenkins
Steve Stuart
Maggie Patterson
Maggie Stuart
Jane Doe
Steve Patterson
Dave Smith
Sam Wilks
Kurt Jefferson
Sam Stuart
Jane Stuart
Dave Davis
Sam Patterson
Tom Jefferson
Jane Stuart
Maggie Jefferson
No Reward Description: (None for No Reward)
Mary Wilks
Neil Patterson
5
Corey Davis
Steve Jacobs
Jane Jenkins
John Jacobs
Neil Smith
Corey Wilks
Corey Smith
Mary Patterson
Jane Stuart
Travis Arnold
John Robinson
Travis Arnold
next(csv_data)
next(csv_data)
for line in csv_data:
if line[0] == 'No Reward':
break
names.append(f"{line[0]} {line[1]}")
John Doe
Dave Smith
Mary Jacobs
Jane Stuart
Tom Wright
Steve Robinson
Nicole Jacobs
Jane Wright
Jane Doe
Kurt Wright
Kurt Robinson
Jane Jenkins
Neil Robinson
Tom Patterson
Sam Jenkins
Steve Stuart
Maggie Patterson
Maggie Stuart
6
Jane Doe
Steve Patterson
Dave Smith
Sam Wilks
Kurt Jefferson
Sam Stuart
Jane Stuart
Dave Davis
Sam Patterson
Tom Jefferson
Jane Stuart
Maggie Jefferson
next(csv_data)
next(csv_data)
for line in csv_data:
if line[0] == 'No Reward':
break
names.append(f"{line[0]} {line[1]}")
html_output += '\n</ul>'
7
t<li>Jane Jenkins</li>
t<li>Neil Robinson</li>
t<li>Tom Patterson</li>
t<li>Sam Jenkins</li>
t<li>Steve Stuart</li>
t<li>Maggie Patterson</li>
t<li>Maggie Stuart</li>
t<li>Jane Doe</li>
t<li>Steve Patterson</li>
t<li>Dave Smith</li>
t<li>Sam Wilks</li>
t<li>Kurt Jefferson</li>
t<li>Sam Stuart</li>
t<li>Jane Stuart</li>
t<li>Dave Davis</li>
t<li>Sam Patterson</li>
t<li>Tom Jefferson</li>
t<li>Jane Stuart</li>
t<li>Maggie Jefferson</li>
[11]:
import csv
html_output = ''
names = []
html_output += '\n<ul>'
html_output += '\n</ul>'
8
print(html_output)
9
15
2021-07-20
21
2
3
2021-07-14
bday = datetime.date(2022,6,12)
28166400.0
1
print(dt)
2021-07-20 23:45:40.010000
tdelta = datetime.timedelta(hours=12)
print(dt + tdelta)
2021-07-21 11:45:40.010000
dt_today = datetime.datetime.today()
dt_now = datetime.datetime.now()
dt_utcnow = datetime.datetime.utcnow()
print(dt_today)
print(dt_now)
print(dt_utcnow)
2021-07-21 02:00:33.616705
2021-07-21 02:00:33.616773
2021-07-21 02:00:33.616807
2021-07-20 23:45:40.010000
2021-07-21 02:03:32.047056+00:00
2021-07-21 02:03:32.047180+00:00
dt_mtn = datetime.datetime.now()
mtn_tz = pytz.timezone('US/Mountain')
dt_mtn = mtn_tz.localize(dt_mtn)
dt_east = dt_mtn.astimezone(pytz.timezone('US/Eastern'))
2
print(dt_mtn.strftime('%B %d, %Y'))
3
16
def test():
y = 'local y'
print(x)
test()
global x
def test():
x = 'local x'
print(x)
test()
print(x)
local x
global x
print(dir(builtins))
m = min([5,1,5,2,3])
print(m)
1
'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError',
'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration',
'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit',
'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError',
'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError',
'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError',
'Warning', 'ZeroDivisionError', '__IPYTHON__', '__build_class__', '__debug__',
'__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__',
'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'breakpoint', 'bytearray', 'bytes',
'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits',
'delattr', 'dict', 'dir', 'display', 'divmod', 'dreload', 'enumerate', 'eval',
'exec', 'execfile', 'filter', 'float', 'format', 'frozenset', 'get_ipython',
'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int',
'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map',
'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow',
'print', 'property', 'range', 'repr', 'reversed', 'round', 'runfile', 'set',
'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple',
'type', 'vars', 'zip']
1
def my_min():
pass
m = min([5,1,5,2,3])
print(m)
inner()
print(x)
outer()
inner x
outer x
2
inner()
print(x)
outer()
print(x)
inner x
outer x
global x
3
17
[2]: li = [9,1,8,2,7,3,6,4,5]
s_li = sorted(li)
print('sorted variable:\t',s_li)
print('original variable:\t',li)
[3]: li = [9,1,8,2,7,3,6,4,5]
s_li = sorted(li)
print('sorted variable:\t',s_li)
li.sort()
print('original variable:\t',li)
[4]: li = [9,1,8,2,7,3,6,4,5]
s_li = sorted(li)
print('sorted variable:\t',s_li)
li.sort(reverse=True)
print('original variable:\t',li)
s_tup = sorted(tup)
print('Tuple:\t',s_tup)
Tuple: [1, 2, 3, 4, 5, 6, 7, 8, 9]
[7]: di = {'name':'Augusto','job':'student','age':26,'os':'windows'}
s_di = sorted(di)
print('Dict\t',s_di)
1
Dict ['age', 'job', 'name', 'os']
[8]: li = [-6,-5,-4,1,2,3]
s_li = sorted(li)
print(s_li)
[9]: li = [-6,-5,-4,1,2,3]
def __repr__(self):
return'{},{},${}'.format(self.name, self.age, self.salary)
e1= Employee('Carl',54,60000)
e2= Employee('Sarah',37,80000)
e3= Employee('John',42,90000)
employees = [e1,e2,e3]
def e_sort(emp):
return emp.name
def __repr__(self):
return'{},{},${}'.format(self.name, self.age, self.salary)
2
e1= Employee('Carl',32,60000)
e2= Employee('Sarah',37,80000)
e3= Employee('John',42,90000)
employees = [e1,e2,e3]
def e_sort(emp):
return emp.salary
def __repr__(self):
return'{},{},${}'.format(self.name, self.age, self.salary)
e1= Employee('Carl',54,60000)
e2= Employee('Sarah',37,80000)
e3= Employee('John',42,90000)
employees = [e1,e2,e3]
def e_sort(emp):
return emp.age
def __repr__(self):
return'{},{},${}'.format(self.name, self.age, self.salary)
3
e1= Employee('Carl',32,60000)
e2= Employee('Sarah',37,80000)
e3= Employee('John',42,90000)
employees = [e1,e2,e3]
def e_sort(emp):
return emp.name
def __repr__(self):
return'{},{},${}'.format(self.name, self.age, self.salary)
e1= Employee('Carl',32,60000)
e2= Employee('Sarah',37,80000)
e3= Employee('John',42,90000)
employees = [e1,e2,e3]
def e_sort(emp):
return emp.name
4
18
[1]: try:
f =open('test_file.txt')
except Exception:
print('Sorry, This file does not exist')
[2]: try:
f =open('test_file.txt')
var = bad_var
except Exception:
print('Sorry, This file does not exist')
[9]: try:
f =open('test_file.txt')
var = bad_var
except FileNotFoundError:
print('Sorry, This file does not exist')
except Exception:
print('Sorry, Somenthing went wrong')
[10]: try:
f =open('test_file.txt')
except FileNotFoundError as e:
print(e)
except Exception as e:
print(e)
else:
print(f.read())
f.close()
1
[11]: try:
f =open('test_file.txt')
except FileNotFoundError as e:
print(e)
except Exception as e:
print(e)
else:
print(f.read())
finally:
print("Executing Finally")
[12]: try:
f =open('currupt_file.txt')
except FileNotFoundError as e:
print(e)
except Exception as e:
print(e)
else:
print(f.read())
finally:
print("Executing Finally")
Currupt File!
Executing Finally