Week2.2

mail@pastecode.io avatar
unknown
python
a year ago
873 B
1
Indexable
Never
Task 1
k = int(input())
i = 1
sum = 0
while i < (k+1):
    sum += i
    i += 1
print(sum)

Task 3
k = int(input())
i = 1
sum = 0
while i < (k * 2 + 1):
    sum += i
    i += 2
print(sum)

Task 5
n = int(input())
f1 = 0
f2 = 1
i = 2
if n == 0:
    print(f1)
elif n == 1:
    print(f2)    
else:
    while i < (n+1):
        f3 = f1 + f2
        f1 = f2
        f2 = f3
        i += 1
    print(f3)

Task 7
list = []
a = input()
while a != '.':
    list.append(a)
    a = input()
print(len(list))

Task 9
summ = 0
k = 0
a = input()
while a != '.':
    summ += int(a)
    k += 1
    a = input()
print(summ/k)

Task 11
summ = 0
a = input()
i = 0
while a != '.':
    if i % 2 == 0:
        summ += float(a)
    i += 1
    a = input()
print(summ)

Task 13
lst = []
a = input()
while a != '.':
    lst.append(float(a))
    a = input()
lst = sorted(lst, reverse=True)
print(lst[1])