Skip to content

Commit 559516e

Browse files
committed
lectie 19.10.2019
1 parent 011c2d5 commit 559516e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

18.10.2019/challenge.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from random import randint
2+
N = int(input("Cate numere vrei sa iti adun?"))
3+
suma = 0
4+
numere = []
5+
for x in range(N):
6+
numere.append(randint(0, 1000))
7+
print(numere)
8+
for x in numere:
9+
suma += x
10+
print(suma)

18.10.2019/cifru_inversare.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mesaj = input('Ce mesaj vrei sa (de)codezi? ')
2+
3+
rezultat = ''
4+
i = len(mesaj) - 1
5+
while i >= 0:
6+
rezultat += mesaj[i]
7+
i = i - 1
8+
9+
print(rezultat)

18.10.2019/codare_cezar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
mesaj = input("Ce mesaj vrei sa codezi? ")
2+
cheie = int(input("Ce cheie vrei sa folosesti? "))
3+
4+
5+
litere = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
6+
7+
alfabet = len(litere)
8+
i = 0
9+
cifrat = ''
10+
11+
def cod(mesaj, codez = 1):
12+
i = 0
13+
marime = len(mesaj)
14+
cif = ''
15+
while i < marime:
16+
nr = (litere.find(mesaj[i]) + codez * cheie) % alfabet
17+
if nr < 0: nr += alfabet
18+
cif += litere[nr]
19+
i += 1
20+
return cif
21+
22+
cifrat = cod(mesaj)
23+
print(cifrat)
24+
decifrat = cod(cifrat, -1)
25+
print(decifrat)

0 commit comments

Comments
 (0)