Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1
- def summa(a):
- s = 0
- for i in a:
- i = int(i)
- s += i
- return s
- a = [1, 7, 42, 12, 10, 1, 4, 0]
- print(summa(a))
- answer: 77
- # 2
- def is_in_range(a, b, x):
- m = 0
- if a < b:
- if x >= a and x <= b:
- m = True
- else:
- m = False
- elif a > b:
- if x >= b and x <= a:
- m = True
- else:
- m = False
- elif a == b:
- if x == a and x == b:
- m = True
- else:
- m = False
- return m
- a, b = map(int, input().split())
- x = int(input())
- print(is_in_range(a, b, x))
- #3
- def dividend(n):
- a = []
- s = 0
- for i in range(1, n):
- if n % i == 0:
- a.append(i)
- for j in a:
- s += j
- return s
- # n = 6
- # print(dividend(n))
- def perfect(n):
- if n > 0 and n == dividend(n):
- a = True
- else:
- a = False
- return a
- n = int(input())
- print(perfect(n))
- answer: True
- #4
- def palindrome(x):
- a = []
- a = [int(i) for i in str(x)]
- k = len(a)
- if k % 2 == 0:
- for j in range(0, k // 2 + 1):
- if a[j] == a[-j-1]:
- an = True
- else:
- an = False
- else:
- an = False
- return an
- x = int(input())
- print(palindrome(x))
- False
- #5
- def simple(n):
- a = []
- for i in range(1, n + 1):
- if n % i == 0:
- a.append(i)
- if len(a) <= 2:
- an = True
- else:
- an = False
- return an
- n = int(input())
- print(simple(n))
- answer: False
- #6
- x = int(input())
- def f(x):
- if x <= 1:
- return 0
- if x <= 3:
- return 1
- else:
- return f(x-1) + f(x - 2)
- print(f(x))
- answer: 34
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement