-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex2.py
More file actions
83 lines (73 loc) · 1.78 KB
/
ex2.py
File metadata and controls
83 lines (73 loc) · 1.78 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
75
76
77
78
79
80
81
82
83
def prob1(x):
# Inverte string usando slicing
rev = x[::-1]
if x != rev:
return False
return True
def prob2(st):
if len(st) < 2:
return ""
return st[0:2] + st[-2:]
def prob3(tp):
return (tp[2],tp[-5])
def prob4(lista):
if not lista:
print("Lista vazia")
else:
print("Lista contem ao menos um elemento")
def prob5(lista):
return "".join(lista)
def prob6_1(numeros):
if len(numeros) < 2:
return -1
fst = -1
scd = -1
for n in numeros:
if n > fst:
scd = fst
fst = n
elif n > scd:
scd = n
return scd
def prob6_2(numeros):
if(len(numeros) < 2):
return -1
numeros.sort(reverse=True)
return(numeros[1])
def prob7_1(dic):
for chave in dic.keys():
if chave == "teste":
print("O valor da chave teste é %(teste)s" %dic)
break
else:
print("Chave não encontrada")
def prob7_2(dic):
if "teste" in dic.keys():
print("O valor da chave teste é %(teste)s" %dic)
else:
print("Chave não encontrada")
def prob7_3(dic):
if "teste" in dic:
print("O valor da chave teste é %(teste)s" %dic)
else:
print("Chave não encontrada")
if __name__ == '__main__':
# print(prob1("arara"))
# print(prob2("asdzxc"))
# print(prob3((1,2,3,4,5,6)))
# prob4([])
# print(prob5(['p','y','t','h','o','n']))
# print(prob6_1([4, 6, 5, 1, 9]))
# print(prob6_2([4, 6, 5, 1, 9]))
d = {'Debian': 'apt-get',
'Ubuntu': 'apt-get',
'Fedora': 'dnf',
'CentOS': 'yum',
'OpenSUSE': 'zypper',
'Arch': 'pacman',
'Gentoo': 'emerge',
'teste': 'encontrado'
}
# prob7_1(d)
prob7_2(d)
prob7_3(d)