Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def main():
- #input some numbers and make a list out of them
- a = input('Enter numbers:')
- a = a.split()
- alist = list(a)
- new_numbers = []
- for n in alist:
- new_numbers.append(int(n))
- alist = new_numbers
- #Create a dictionary to count the number of instances each number occurs
- newlist = {}
- for i in alist:
- if i in newlist:
- newlist[i]+=1
- else:
- newlist[i] = 1
- #list2 contains the values that were actually inputted
- list2 = list(newlist.keys())
- #list3 has how many times that value occurs
- list3 = list(newlist.values())
- #this for loop prints out how many times each number from the output occurred
- for x in range(len(list2)):
- if list3[x] > 1:
- print(list2[x],'occurs',list3[x],'times')
- if list3[x] == 1:
- print(list2[x],'occurs',list3[x],'time')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement