Advertisement
vallec

1

Jan 9th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #import random
  2. from random import randint
  3.  
  4. arr = []
  5.  
  6. while True:
  7. try:
  8. n = int(input("Vavedi n: "))
  9. if(n < 30 or n > 100):
  10. print("Chisloto trqbva da e mejdu 30 i 100")
  11. break
  12. except ValueError:
  13. print("Vavedete chislo!")
  14. break
  15. except Exception:
  16. print("Nevalidni vhodni danni!")
  17. break
  18.  
  19.  
  20. minRandom = 20
  21. maxRandom = 600
  22.  
  23. for _ in range(n):
  24. arr.append(randint(minRandom, maxRandom))
  25.  
  26. kratni2 = 0
  27. minEl = maxRandom + 10
  28. minIndex = 0
  29.  
  30. # 456 % 10 -> 6 % 2 == 0
  31.  
  32. for i in range(len(arr)):
  33. if((arr[i] % 10) % 2 == 0):
  34. kratni2 = kratni2 + 1
  35. if(arr[i] % 7 == 3 and arr[i] < minEl):
  36. minIndex = i
  37. minEl = arr[i]
  38.  
  39. print(f"Broi elementi, chiqto cifra na edinicite e kratna na 2: {kratni2}")
  40. print(f"Index na minimalen element, koito ima ostatuk 3 pri delenie na 7: {minIndex}")
  41.  
  42. # 456 / 100 -> 4.56 -> 4
  43. # 456 % 100 -> 56 / 10 -> 5.6 -> 5
  44.  
  45. arr2 = [num for num in arr if num // 100 == 3 or (num % 100) // 10 == 5]
  46. print(f"Arr2: {arr2}")
  47.  
  48. maxEl = arr2[0]
  49. maxIndex = 0
  50. for i in range(1, len(arr2)):
  51. if(arr2[i] > maxEl):
  52. maxEl = arr2[i]
  53. maxIndex = i
  54. print(f"Indexa na elementa s max stoinost: {maxIndex}")
  55.  
  56. proizvElEdinici3 = 1
  57.  
  58. for i in range(len(arr2)):
  59. if(arr2[i] % 10 == 3):
  60. proizvElEdinici3 = proizvElEdinici3 * arr2[i]
  61.  
  62. print(f"Proizv na elementite s cifra na edinicite 3: {proizvElEdinici3}")
  63.  
  64. break
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement