94 lines
1.7 KiB
Python
94 lines
1.7 KiB
Python
# %%
|
|
## Task 1
|
|
a=-5
|
|
while a < 6:
|
|
print(a)
|
|
a+=1
|
|
|
|
# %%
|
|
## Task 2.1
|
|
counter=0
|
|
for a in range(10):
|
|
for b in range(5):
|
|
counter+=1
|
|
|
|
print(counter)
|
|
|
|
# %%
|
|
## Task 2.2
|
|
a=0;b=0;counter=0
|
|
while a < 4:
|
|
b=0
|
|
while b < 8:
|
|
counter+=1
|
|
b+=1
|
|
a+=1
|
|
|
|
print(counter)
|
|
|
|
# %%
|
|
## Task 2.3
|
|
L = ["A", "B", "C", "D", "E"]
|
|
a = 0
|
|
while a < len(L):
|
|
print(L[a])
|
|
a+=1
|
|
|
|
# %%
|
|
## Task 2.4
|
|
L = ["A", "B", "C", "D", "E"]
|
|
for item in L:
|
|
print(item)
|
|
|
|
# %%
|
|
## Task 3.1
|
|
mylist = [2, 11, 12, 45, 52, 808, 7, 68, 91, 1013]
|
|
a=0
|
|
for item in mylist:
|
|
if item % 2 == 0:
|
|
mylist[a] = int(item / 2)
|
|
a+=1
|
|
print(mylist)
|
|
|
|
# %%
|
|
## Task 3.2
|
|
first_names = ["Lisa", "Bob", "Carl", "Mohammed", "Vlad", "Aina"]
|
|
last_names = ["Smith", "Zhang", "Karlson", "Lee", "Numan", "Musa"]
|
|
a=0
|
|
while a < len(first_names):
|
|
print(first_names[a]+" "+last_names[a])
|
|
a+=1
|
|
|
|
# %%
|
|
## Task 3.3
|
|
first_names = ["Lisa", "Bob", "Carl", "Mohammed", "Vlad", "Aina"]
|
|
last_names = ["Smith", "Zhang", "Karlson", "Lee", "Numan", "Musa"]
|
|
first_names_mapped = [2,3,4,5,0,1]
|
|
a=0
|
|
while a < len(last_names):
|
|
print(first_names[first_names_mapped[a]]+" "+last_names[a])
|
|
a+=1
|
|
|
|
# %%
|
|
## Task 4.1
|
|
alist = [4, 5, 88, 32, 99, 88, 73, 68, 91, 1024]
|
|
for item in alist:
|
|
a=0;temp=item
|
|
while temp % 2 == 0:
|
|
temp = temp // 2
|
|
print(temp)
|
|
|
|
# %%
|
|
## Task 4.2
|
|
user_input = int(input("Enter number greater than 2: "))
|
|
print(2)
|
|
for x in range(2,user_input):
|
|
## if a odd number
|
|
if x % 2 != 0:
|
|
num=2
|
|
## look for all numbers where it is not evenly divisible
|
|
while x % num != 0:
|
|
num+=1
|
|
## if above loop ends and all numbers are exhausted, you have a prime
|
|
if x == num:
|
|
print(x) |