Advertisement
sigmachto

Untitled

Jul 11th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. # 1)
  2.  
  3. def f(a,b):
  4.     return 18 * a * b
  5. print(f(1,4))
  6. #Ответ: 2
  7.  
  8. #2)
  9. summa = 0
  10. for i in range(1,11):
  11.     summa += i
  12. print('The sum is',  summa)
  13. #Ответ: 3
  14.  
  15. #3)
  16. def is_even(n):
  17.     if n % 2 == 0:
  18.         return (n,'is even')
  19.     else:
  20.         return (n, "is odd")
  21. print(is_even(int('4')))
  22. #Ответ: 3
  23.  
  24. #4)
  25. def factorial(n):
  26.     if n < 0:
  27.         return None
  28.     if n == 0:
  29.         return 1
  30.     else:
  31.         return n * factorial(n - 1)
  32. print(factorial(int(input())))
  33.  
  34. #5)
  35. def is_palindrom(s):
  36.     s = s.lower()
  37.     for i in range(len(s)):
  38.         if s[i] != s[len(s) - i - 1]:
  39.             return False
  40.     return True
  41. print(is_palindrom('шалаш'))
  42. #6)
  43. def multiplylist(lst):
  44.     if len(lst) == 0:
  45.         return None
  46.     else:
  47.         result = 1
  48.         for i in range(len(lst)):
  49.             result = result * lst[i]
  50.         return result
  51. print(multiplylist([1,2,3,4,5]))
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement