Advertisement
aed1oN

Untitled

Oct 20th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. '''
  2. Mode: most common number in a list
  3. '''
  4.  
  5. def main():
  6. #-------------------------------------------------------------------------
  7. # TODO Write your code in this space, and only in this space!
  8. # You may expand this space as needed.
  9. # Do not modify anything else outside of this space.
  10. # reading from input
  11. input_data = []
  12. for i in range(0, 10):
  13. input_data.append(int(input("Enter your number: ")))
  14.  
  15. # sorting
  16. for i in range(0, len(input_data)):
  17. key = input_data[i]
  18. j = i - 1
  19. while j >= 0 and key < input_data[j]:
  20. input_data[j + 1] = input_data[j]
  21. j = j - 1
  22. input_data[j + 1] = key
  23. print("Numbers you entered are: ", input_data)
  24.  
  25. # numbers without repetition
  26. without_rep_list = []
  27. for i in range(0, len(input_data) - 1):
  28. for j in range(i + 1, len(input_data)):
  29. if input_data[i] != input_data[j]:
  30. without_rep_list.append(input_data[i])
  31. break
  32. for i in range(0, len(without_rep_list)):
  33. if input_data[-1] != without_rep_list[i]:
  34. f = 1
  35. else:
  36. f = 0
  37. break
  38. if f == 1:
  39. without_rep_list.append(input_data[-1])
  40. print(without_rep_list)
  41.  
  42. # counting repeting elements
  43. previous = input_data[0]
  44. counter = 0
  45. counter_list = []
  46. for i in range(0, len(input_data)):
  47. if previous == input_data[i]:
  48. counter = counter + 1
  49. else:
  50. print(previous, " : ", counter)
  51. counter_list.append(counter)
  52. previous = input_data[i]
  53. counter = 1
  54.  
  55. counter_list.append(counter)
  56. print(previous, " : ", counter)
  57. maximum = 0
  58. for i in range(0, len(counter_list)):
  59. if counter_list[i] > maximum:
  60. maximum = counter_list[i]
  61. j = i
  62. print("Most common element is: ", without_rep_list[j])
  63.  
  64.  
  65. #-------------------------------------------------------------------------
  66. return
  67.  
  68. if __name__ == "__main__":
  69. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement