Advertisement
farrismp

Counting

Apr 30th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. from random import randint
  2.  
  3. # My function
  4. def count(item, scores):
  5. count = 0
  6. for score in scores:
  7. if score == item:
  8. count += 1
  9. return count
  10. # End of my function
  11.  
  12.  
  13. # Generate a 30 random numbers from 0 to 10 and append to scores
  14. scores = []
  15. for x in range (0, 30):
  16. scores.append(randint(0, 10))
  17. print(scores)
  18.  
  19. # Count a target numbers
  20. target = int(input("What score do you want to check for "))
  21. top_scorers = count(target,scores)
  22.  
  23. print("{} learners got {} marks".format(top_scorers, target))
  24.  
  25. # Count in a range
  26. lows = 0
  27. tot_low = 0
  28. for loop in range(0,3): # Counts scores less than 3
  29. lows = count(loop,scores)
  30. tot_low= tot_low + lows
  31. print("{} learners got less than 3 marks ".format(tot_low))
  32.  
  33. # Accept a word and count the number of vowels
  34. word = input("Give me a word ")
  35. vowels ="aeiou"
  36.  
  37. tot = 0
  38. for vowel in vowels:
  39. temp = count(vowel, word)
  40. tot = tot + temp
  41.  
  42. print("There are {} vowels in {} ".format(tot, word))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement