Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Fall 2006 Midterm 2 Review: String Stuff

Post your questions here.



def countAs(string):
  count=0
  for i in string:
    if i=="a":
      count=count+1
  print count

def countVowels(string):
  vowels="aeiou"
  count=0
  for i in string:
    for v in vowels:
      if i==v:
        count=count+1
  print count

Jeffrey Wells

The code is right except you need to do 'return count' instead of 'print count' in both the cases. - Bobby Mathew



def countAs(string):
   count = string.count(“a”)
   return count 

Yup, that's another way to do it. But make sure you know how to do it with loops as well. - Bobby Mathew

2.
def countAs (string):
    value=0
    for i in list:
      if i =="a" or i=="e" or i=="i" or i=="o" or i=="u"
        value=value+1
    return value

Stacy Schwaiger

Your loop should be 'for i in string' and there should be a ':' after your 'if' statement. - Bobby Mathew




Link to this Page