Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def count(mark, scores):
- numbers = 0 # Initialise a variable for counting scores of ten
- for score in scores:
- if score == mark:
- numbers += 1
- def range_count(scores):
- print("Which range do you want to find?")
- print("Below value entered, type : l")
- print ("Above value entered, type : a")
- print("Between values, enter : v")
- request = input(":>")
- numbers = 0 # Initialise a variable for counting scores lower than mark
- if request == "l":
- mark = input("Enter mark :> ")
- for score in scores:
- if score < int(mark):
- numbers += 1
- mark = str(mark)
- output = "low scores, lower than " #+ mark
- elif request == "a":
- mark = input("Enter mark :> ")
- for score in scores:
- if score > int(mark):
- numbers += 1
- mark = str(mark)
- output = "higher scores, higher than " #+ mark
- elif request == "v":
- high = int(input("enter high value :> "))
- low = int(input("enter low value :> "))
- for score in scores:
- if (score >= low and score <= high):
- numbers += 1
- mark = str(low) + " and " + str(high)
- output = "score between the marks specified " + mark
- else:
- print(" you really do need to choose from the options given")
- numbers = 0
- mark = "none"
- output = "XXX No count done, instructions not followed"
- return numbers, output
- scores = []
- for x in range (0, 30):
- scores.append(randint(0, 10)) # Generate a random number from 0 to 10 and append to scores
- print("This is the list of scores for the class", scores)
- mark = int(input("\nEnter the mark you are searching for, 10 is top :> "))
- search_item = 0 # Initialise a variable for counting scores of ten
- for score in scores:
- if score == mark:
- search_item += 1
- top_scorers = count(mark, scores) # Count function called here
- print("{0} learners got top marks".format(search_item))
- print("\nSearhing..., counting values in range in a list?")
- numbers, output = range_count(scores) # count function called for ranges
- print("{0} learners got ".format(numbers), output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement