Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 56420e4

Browse files
committed
Add files via upload
1 parent 2e5d61f commit 56420e4

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

Homework 2/Ex1.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def your_function():
2+
return 0
3+
4+
5+
def your_function2(p1, p2, p3, *args):
6+
s = p1 + p2 + p3
7+
return s
8+
9+
10+
def your_function3(p1, p2, *args, **kargs):
11+
s = p1 + p2
12+
return s
13+
14+
15+
def main():
16+
nr1 = your_function2(1, 5, -3, 'abc', [12, 56, 'cad'])
17+
print(nr1)
18+
nr2 = your_function()
19+
print(nr2)
20+
nr3 = your_function3(2, 4, 'abc', param_1=2)
21+
print(nr3)
22+
23+
24+
main()

Homework 2/Ex2.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
def sum_of_nr(nr):
2+
s = 0
3+
s_Even = 0
4+
s_Odd = 0
5+
for i in range(0, nr + 1):
6+
s = s + i
7+
if i % 2 == 0:
8+
s_Even = s_Even + i
9+
else:
10+
s_Odd = s_Odd + i
11+
12+
print("The sum is ", s)
13+
print("The sum of even numbers is ", s_Even)
14+
print("The sum of odd numbers is ", s_Odd)
15+
16+
17+
def main():
18+
try:
19+
nr = int(input("Enter a integer:"))
20+
sum_of_nr(nr)
21+
except ValueError:
22+
print("The number must be a integer")
23+
else:
24+
print("The code work!")
25+
26+
27+
main()

Homework 2/Ex3.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def read():
2+
try:
3+
n = int(input("Enter something:"))
4+
except ValueError:
5+
print("Is not a integer")
6+
return 0
7+
else:
8+
return n
9+
10+
11+
def main():
12+
n = read()
13+
print(n)
14+
15+
16+
main()

Week2/Intro.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
message = "Ana\'s have oranges"
2+
print(message)
3+
no_orange = 2
4+
message = f'Ana\'s have {no_orange} oranges' # the most usable
5+
print(message)
6+
no_cherr = 5
7+
message = "Ana have {0} oranges and {1} cherries".format(no_orange, no_cherr)
8+
print(message)
9+
10+
list = [4, 2, 3, 'Ana', 5]
11+
print(list[0:2:1])
12+
list[0] = 10
13+
print(list[:])
14+
15+
# tuple1 = (1) # immutable
16+
# print(type(tuple1)) # one element is like int
17+
tuple = (1, -3, 'a') # selectors django are tuple
18+
19+
dictionary = {"key1": 1, "key2": 2}
20+
print(dictionary.get("key3", 3))
21+
print(dictionary)
22+
dictionary["key3"] = 3
23+
print(dictionary)
24+
dictionary.update({"key4": 4})
25+
print(dictionary.values())
26+
print(dictionary.keys())
27+
print(dictionary.items())
28+
29+
set1 = {"item", 1, 2, 3} # immutable
30+
set2 = {"item", 2, -1}
31+
print(set1.intersection(set2))
32+
print(set1.union(set2))
33+
print(set2.difference(set1))
34+
35+
my_var = 3
36+
m = "conditii false"
37+
if my_var < 5:
38+
m = "mai mic"
39+
elif my_var > 4:
40+
m = "mai mare"
41+
42+
print(m)
43+
44+
variabila_1 = 1
45+
while variabila_1 < 3:
46+
print("Instruction")
47+
variabila_1 = variabila_1 + 1
48+
49+
cuvant = "Ana are mere"
50+
for x, value in enumerate(cuvant):
51+
print(x, value)
52+
53+
for i in range(0, 10, 2):
54+
print(i)

Week2/Spanzuratoarea.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cuvant = "alfabet"
2+
# cuvant = 'a__a__t'
3+
cuvant_ascuns = []
4+
for i in cuvant:
5+
# print(cuvant[0],cuvant[-1])
6+
if cuvant[0] != i and cuvant[-1] != i:
7+
cuvant_ascuns.append('_')
8+
else:
9+
cuvant_ascuns.append(i)
10+
print("".join(cuvant_ascuns))
11+
count_nr = 1
12+
set_litere_deja_incercate = set()
13+
while count_nr <= len(cuvant):
14+
15+
user_letter = input("Alege o litera: ")
16+
# print(user_letter)
17+
if user_letter in set_litere_deja_incercate:
18+
print("Litera deja incercata")
19+
continue
20+
if user_letter in cuvant:
21+
for iterator, value in enumerate(cuvant):
22+
# print(iterator,value)
23+
if cuvant[iterator] == user_letter:
24+
cuvant_ascuns[iterator] = user_letter
25+
print(" ".join(cuvant_ascuns))
26+
else:
27+
count_nr = count_nr + 1
28+
29+
if '_' not in cuvant_ascuns:
30+
print("Ai castigat!")
31+
break
32+
33+
elif count_nr == len(cuvant):
34+
print(f'Ai pierdut! Cuvantul era {cuvant}')
35+
set_litere_deja_incercate.add(user_letter)
36+

0 commit comments

Comments
 (0)