Advertisement
scarygarey

top scores and counting vowels

Jan 12th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Name: module2
  3. # Purpose:
  4. #
  5. # Author: DGarey
  6. #
  7. # Created: 12/01/2020
  8. # Copyright: (c) DGarey 2020
  9. # Licence: <your licence>
  10. #-------------------------------------------------------------------------------
  11.  
  12. from random import randint
  13.  
  14. scores = []
  15.  
  16. for x in range (0, 30):
  17. scores.append(randint(0, 10)) # Generate a random number from 0 to 10 and append to scores
  18.  
  19. print(scores)
  20.  
  21. tens = 0 # Initialise a variable for counting scores of ten
  22.  
  23. for score in scores:
  24. if score == 10:
  25. tens += 1
  26.  
  27. print(str(tens) + " learners got top marks")
  28.  
  29. import random
  30.  
  31. #
  32. # Add your count function here
  33. def count(number, list):
  34. count = 0 # Initialise a variable for counting scores of ten
  35.  
  36. for item in list:
  37. if item == number:
  38. count += 1
  39. return(count)
  40. #
  41.  
  42. scores = []
  43.  
  44. for x in range (0, 30):
  45. scores.append(random.randint(0, 10))
  46.  
  47. print(scores)
  48.  
  49. top_scorers = count(10, scores) # Count function called here
  50.  
  51. print(str(top_scorers) + " learners got top marks")
  52.  
  53. #What about counting occurrences of a given item in a list of strings?
  54.  
  55. word = "up the villa"
  56.  
  57. vowels = ["a","e","i","o","u"]
  58.  
  59. def count(word,list):
  60. counter = 0
  61. for each in word:
  62. if each in vowels:
  63. counter = counter + 1
  64. return counter
  65.  
  66. number = count(word,vowels)
  67. print("The number of vowels in {} is {}.".format(word,number))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement