Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- # My function
- def count(item, scores):
- count = 0
- for score in scores:
- if score == item:
- count += 1
- return count
- # End of my function
- # Generate a 30 random numbers from 0 to 10 and append to scores
- scores = []
- for x in range (0, 30):
- scores.append(randint(0, 10))
- print(scores)
- # Count a target numbers
- target = int(input("What score do you want to check for "))
- top_scorers = count(target,scores)
- print("{} learners got {} marks".format(top_scorers, target))
- # Count in a range
- lows = 0
- tot_low = 0
- for loop in range(0,3): # Counts scores less than 3
- lows = count(loop,scores)
- tot_low= tot_low + lows
- print("{} learners got less than 3 marks ".format(tot_low))
- # Accept a word and count the number of vowels
- word = input("Give me a word ")
- vowels ="aeiou"
- tot = 0
- for vowel in vowels:
- temp = count(vowel, word)
- tot = tot + temp
- print("There are {} vowels in {} ".format(tot, word))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement