Advertisement
Dido09

Задачи

Jan 7th, 2022
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. ЗАДАЧА 1.
  2. /////////////////////////////////////////////////////////////////
  3. lst = []
  4. AmountOfNumbers = int(input('How many numbers: '))
  5. for n in range(AmountOfNumbers):
  6. numbers = int(input('Enter number '))
  7. lst.append(numbers)
  8. print("Biggest element in the list is :", max(lst))
  9.  
  10. /////////////////////////////////////////////////////////////////
  11. ЗАДАЧА 2.
  12. /////////////////////////////////////////////////////////////////
  13. lst = []
  14. SumOfNumbers = int(input('Enter the numbers that you wish to sum: '))
  15. for n in range(SumOfNumbers):
  16. numbers = int(input('Enter a number: '))
  17. lst.append(numbers)
  18.  
  19. print('The sum of the numbers is: ', sum(lst))
  20.  
  21. ///////////////////////////////////////////////////////////////////
  22.  
  23. ЗАДАЧА 3.
  24. //////////////////////////////////////////////////////////////////
  25. n = int(input("Enter the amount of rows for the triangle: "))
  26.  
  27. for i in range(0, n):
  28. for j in range(0, i + 1):
  29. print("* ", end="")
  30.  
  31. print()
  32. /////////////////////////////////////////////////////////////////
  33. ЗАДАЧА 4.
  34. /////////////////////////////////////////////////////////////////
  35. primeNumber = int(input("Enter a number: "))
  36.  
  37. # prime numbers are greater than 1
  38. if primeNumber > 1:
  39. # check for factors
  40. for i in range(2, primeNumber):
  41. if (primeNumber % i) == 0:
  42. print(primeNumber, "is not a prime number")
  43. print(i, "times", primeNumber // i, "is", primeNumber)
  44. break
  45. else:
  46. print(primeNumber, "is a prime number")
  47.  
  48. # if input number is less than
  49. # or equal to 1, it is not prime
  50. else:
  51. print(primeNumber, "is not a prime number")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement