Advertisement
fabis_sparks

Maria Task 3

Mar 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import random
  2. arr=[]
  3. size_arr=int(input('Input size of array: '))
  4. for i in range(size_arr):
  5.     arr.append(random.randint(-50,50))
  6. print(arr)
  7. positive=0
  8. negative=0
  9. #Count how many pos. and neg. numbers
  10. for i in range(size_arr):
  11.     if (arr[i]>0): positive=positive+1
  12.     if (arr[i]<0): negative+=1
  13. # Show us total
  14. print('Positives: ', positive)
  15. print('Negatives: ', negative)
  16. #If pos less than neg, then generate some pos numbers and add to array
  17. if (positive<negative):
  18.     for i in range(negative-positive):
  19.         arr.append(random.randint(1,50))
  20. #All the same
  21. if (positive>negative):
  22.     for i in range(positive-negative):
  23.         arr.appned(random.randint(-50,-1))
  24. #Print resulting array
  25. print(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement