Advertisement
imariia777

Untitled

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