Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def task1_1(lst):
- res = []
- for i in range(len(lst)):
- res += lst[i:][::-1]
- return res
- def task1_2(lst):
- res = []
- for i in range(len(lst)):
- for j in range(len(lst)-1, i-1, -1):
- res.append(lst[j])
- return res
- def task2(lst):
- if type(lst) == list: # если lst - это список
- ans = 0
- for x in lst:
- ans += task2(x)
- return ans
- return lst # если lst - это число
- def task3(lst):
- res = []
- n = len(lst)
- for i in range(n):
- res.append(lst[i])
- for j in range(i+1, n):
- res[i] *= lst[j]
- return res
- a = [1, 2, 3, 4, 5, 6]
- print(task3(a))
- # Способ 1: если элементы вводятся в одной строке через пробел
- # a = list(map(int, input().split()))
- # Способ 2:
- # в строке 1 - подается число элементов - n
- # n = int(input())
- # затем подается n строк: по одному элементу в строке
- # a = [ int(input()) for i in range(n) ]
- # Способ 3
- # элементы считываются пока не будет получено какое-то значение (например, 0)
- # x = int(input())
- # a = []
- # while x != 0:
- # a.append(x) # добавление в конце списка
- # x = int(input())
Advertisement
Add Comment
Please, Sign In to add comment