Advertisement
kevinbocky

highscore_lowscore_reoccurrence.py

Jan 27th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. import random #import from the random function
  2.  
  3. grades = [] #create empty list called grades
  4. tens = [] #create empty list called tens
  5. lowscore = []
  6. for x in range(0, 30): # loop range 30
  7. grades.append(random.randint(0,10)) #append in grades a random number 0 - 10
  8.  
  9. print(grades)
  10.  
  11. for item in grades: #for every item in grades, if equal to 10, put in tens list
  12. if item == 10:
  13. tens.append(item)
  14. elif item <= 3:
  15. lowscore.append(item) #for every item in grades if lower then 3 put in lowscore list
  16.  
  17. print(tens)
  18. top_scorers = len(tens) #top_scorers is equal to the length of tens list(int)
  19. low_scorers = len(lowscore) #low_scorers is equal to the length of lowscore list
  20. print(" {} student/s have scored the perfect score".format(top_scorers))
  21. print(" {} student/s have scored lower then 3".format(low_scorers))
  22.  
  23.  
  24.  
  25. #find a way to display the most populair item
  26. from collections import Counter #import Counter from collections
  27.  
  28. order_drinks = ["Tea","Coffee","Tea","Tea","Coffee","Hot Chocolate","Tea"] #this is the list
  29.  
  30.  
  31. i = Counter(order_drinks) #using a class constructor __init__ ?
  32. print(i.most_common()) #display the most common value, in order from high to low
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement