Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. # Print the first letter of the following string
  2.  
  3. school = "McHenry County College"
  4.  
  5. print school[0]
  6.  
  7.  
  8.  
  9. # print the length of the school string
  10.  
  11. print len (school)
  12.  
  13. # Use a while loop to print each character (including spaces) in the school variable
  14. i = 0
  15. while i < len (school):
  16. letter = school[i]
  17. print letter
  18. i = i + 1
  19.  
  20. # Slice school into three variables, print the variables
  21.  
  22. print school[0:7], school[8:14], school[15:22]
  23.  
  24. # use a while statement to search for the letter "e" in the contents of the school variable
  25. index = 0
  26. while index < len (school):
  27. if school[index] == str('e'):
  28. print index
  29. index = index +1
  30.  
  31.  
  32. # print the index of every location with the letter "e"
  33. # is this not the same problem as above?
  34.  
  35.  
  36. # rembember, you should not use the same variable twice in the same program
  37. # so if you used the variable index, use something else
  38.  
  39.  
  40.  
  41. # Write the code to count the number of times the letter y appears in the school variable
  42. # print the total
  43. counter = 0
  44. for letter in school:
  45. if letter == 'y':
  46. counter = counter + 1
  47. print counter
  48.  
  49.  
  50. # create a variable named college and store the upper case version of the variable school in it
  51. college = school.upper()
  52.  
  53. # check to see if Count is in the school variable
  54. def checkupper():
  55. if 'Count' in school:
  56. print "True"
  57. else:
  58. print 'False'
  59.  
  60. checkupper()
  61.  
  62.  
  63. # check to see if count is in the school variable
  64.  
  65. def checklower():
  66. if 'count' in school:
  67. print "True"
  68. else:
  69. print 'False'
  70. checklower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement