Advertisement
imariia777

Untitled

Jul 19th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. #1
  2. def summa(a):
  3.     s = 0
  4.     for i in a:
  5.         i = int(i)
  6.         s += i
  7.     return s
  8. a = [1, 7, 42, 12, 10, 1, 4, 0]
  9. print(summa(a))
  10. answer: 77
  11.  
  12. # 2
  13. def is_in_range(a, b, x):
  14.     m = 0
  15.     if a < b:
  16.         if x >= a and x <= b:
  17.             m = True
  18.         else:
  19.             m = False
  20.     elif a > b:
  21.         if x >= b and x <= a:
  22.             m = True
  23.         else:
  24.             m = False
  25.     elif a == b:
  26.         if x == a and x == b:
  27.             m = True
  28.         else:
  29.             m = False
  30.     return m
  31.  
  32.  
  33. a, b = map(int, input().split())
  34. x = int(input())
  35. print(is_in_range(a, b, x))
  36.  
  37. #3
  38. def dividend(n):
  39.     a = []
  40.     s = 0
  41.     for i in range(1, n):
  42.         if n % i == 0:
  43.             a.append(i)
  44.     for j in a:
  45.         s += j
  46.     return s
  47. # n = 6
  48. # print(dividend(n))
  49.  
  50. def perfect(n):
  51.     if n > 0 and n == dividend(n):
  52.         a = True
  53.     else:
  54.         a = False
  55.     return a
  56. n = int(input())
  57. print(perfect(n))
  58. answer: True
  59.  
  60. #4
  61. def palindrome(x):
  62.     a = []
  63.     a = [int(i) for i in str(x)]
  64.     k = len(a)
  65.     if k % 2 == 0:
  66.         for j in range(0, k // 2 + 1):
  67.             if a[j] == a[-j-1]:
  68.                 an = True
  69.             else:
  70.                 an = False
  71.     else:
  72.         an = False
  73.     return an
  74.  
  75. x = int(input())
  76. print(palindrome(x))
  77. False
  78.  
  79. #5
  80. def simple(n):
  81.     a = []
  82.     for i in range(1, n + 1):
  83.         if n % i == 0:
  84.             a.append(i)
  85.     if len(a) <= 2:
  86.         an = True
  87.     else:
  88.         an = False
  89.     return an
  90.  
  91. n = int(input())
  92. print(simple(n))
  93. answer: False
  94.  
  95. #6
  96. x = int(input())
  97. def f(x):
  98.     if x <= 1:
  99.         return 0
  100.     if x <= 3:
  101.         return 1
  102.     else:
  103.         return f(x-1) + f(x - 2)
  104. print(f(x))
  105. answer: 34
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement