Guest User

Untitled

a guest
Aug 25th, 2019
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from random import randint
  2.  
  3. def count(mark, scores):
  4. numbers = 0 # Initialise a variable for counting scores of ten
  5. for score in scores:
  6. if score == mark:
  7. numbers += 1
  8.  
  9. def range_count(scores):
  10. print("Which range do you want to find?")
  11. print("Below value entered, type : l")
  12. print ("Above value entered, type : a")
  13. print("Between values, enter : v")
  14. request = input(":>")
  15. numbers = 0 # Initialise a variable for counting scores lower than mark
  16. if request == "l":
  17. mark = input("Enter mark :> ")
  18. for score in scores:
  19. if score < int(mark):
  20. numbers += 1
  21. mark = str(mark)
  22. output = "low scores, lower than " #+ mark
  23. elif request == "a":
  24. mark = input("Enter mark :> ")
  25. for score in scores:
  26. if score > int(mark):
  27. numbers += 1
  28. mark = str(mark)
  29. output = "higher scores, higher than " #+ mark
  30. elif request == "v":
  31. high = int(input("enter high value :> "))
  32. low = int(input("enter low value :> "))
  33. for score in scores:
  34. if (score >= low and score <= high):
  35. numbers += 1
  36. mark = str(low) + " and " + str(high)
  37. output = "score between the marks specified " + mark
  38. else:
  39. print(" you really do need to choose from the options given")
  40. numbers = 0
  41. mark = "none"
  42. output = "XXX No count done, instructions not followed"
  43. return numbers, output
  44.  
  45. scores = []
  46.  
  47. for x in range (0, 30):
  48. scores.append(randint(0, 10)) # Generate a random number from 0 to 10 and append to scores
  49. print("This is the list of scores for the class", scores)
  50.  
  51. mark = int(input("\nEnter the mark you are searching for, 10 is top :> "))
  52. search_item = 0 # Initialise a variable for counting scores of ten
  53.  
  54. for score in scores:
  55. if score == mark:
  56. search_item += 1
  57.  
  58. top_scorers = count(mark, scores) # Count function called here
  59.  
  60. print("{0} learners got top marks".format(search_item))
  61.  
  62. print("\nSearhing..., counting values in range in a list?")
  63. numbers, output = range_count(scores) # count function called for ranges
  64. print("{0} learners got ".format(numbers), output)
RAW Paste Data