Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- # function to count a specific grade
- def my_count(tgt, list):
- cnt = 0
- for sc in list:
- if sc == tgt:
- cnt +=1
- print(f"{cnt} learners with a score of {tgt}")
- # function to count all grades, so just needs on parameter
- def my_count_all(list):
- for tgt in range(10,-1,-1): # to start at 10 and stop at 0
- cnt = 0
- for sc in list:
- if sc == tgt:
- cnt +=1
- print(f"{cnt} learners with a score of {tgt}")
- print("__")
- print(f"{len(scores)} learners altogether")
- print("==")
- # function to count a grade range
- def my_count_range(minz, maxz, list):
- cnt = 0
- for sc in list:
- if sc in range(minz,maxz):
- cnt +=1
- print(f"{cnt} learners with a score above {minz} and below {maxz}")
- # function to count vowles in a word
- def count_vowels(word):
- cnt = 0
- for i in range(0,len(word)):
- if word[i].lower() in my_vowels:
- cnt +=1
- print(f"there are {cnt} vowels in the word {word}")
- my_list_of_towns = ["Blackfield","Whitefield","Greyfield","Nofield", "Bigfield", "Blackfield"]
- scores = []
- my_vowels = ["a", "e", "i", "o", "u"]
- for x in range (0, 30):
- scores.append(randint(0, 10)) # Generate a random number from 0 to 10 and append to scores
- #print(scores)
- '''
- for score in scores:
- if score == 10:
- tens +=1
- '''
- #print(scores.count(10)) testing
- #print(f"{tens} learners got top marks")
- # function call my_count
- #my_count(10,scores)
- #my_count(9,scores)
- #my_count(8,scores)
- #my_count(7,scores)
- # function call my_count_all
- my_count_all(scores)
- # function call for my_count_range
- my_count_range(0,11,scores) ## not to self, starts at first value, stops before the second
- # call using my_list_of_towns list - works but should have narative changed
- my_count("Blackfield",my_list_of_towns)
- ##my_count("grapes", my_vowels) didnt work! going to create a new function
- # calling count_vowels
- count_vowels("Argh")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement