Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Name: module2
- # Purpose:
- #
- # Author: DGarey
- #
- # Created: 12/01/2020
- # Copyright: (c) DGarey 2020
- # Licence: <your licence>
- #-------------------------------------------------------------------------------
- from random import randint
- 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(scores)
- tens = 0 # Initialise a variable for counting scores of ten
- for score in scores:
- if score == 10:
- tens += 1
- print(str(tens) + " learners got top marks")
- import random
- #
- # Add your count function here
- def count(number, list):
- count = 0 # Initialise a variable for counting scores of ten
- for item in list:
- if item == number:
- count += 1
- return(count)
- #
- scores = []
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- print(scores)
- top_scorers = count(10, scores) # Count function called here
- print(str(top_scorers) + " learners got top marks")
- #What about counting occurrences of a given item in a list of strings?
- word = "up the villa"
- vowels = ["a","e","i","o","u"]
- def count(word,list):
- counter = 0
- for each in word:
- if each in vowels:
- counter = counter + 1
- return counter
- number = count(word,vowels)
- print("The number of vowels in {} is {}.".format(word,number))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement