teromakotero

Count numbers and characters in string

May 8th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import random
  2.  
  3. def count(num,scores):
  4.     number = num
  5.     count = 0
  6.     for i in scores:
  7.         if(i == number):
  8.             count += 1
  9.     return count
  10.        
  11.  
  12. scores = []
  13.  
  14. for x in range (0, 30):
  15.   scores.append(random.randint(0, 10))
  16.  
  17. print(scores)
  18.  
  19. top_scorers = count(10, scores) # Count function called here
  20.  
  21. print("{0} learners got top marks".format(top_scorers))
  22.  
  23. string = "Can you find the letters"
  24.  
  25. print(count('e',string), " letter e's in the string.")
Advertisement
Add Comment
Please, Sign In to add comment