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


This page removed for FERPA compliance
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 countREMOVEDwels(string):
  vowels="aeiou"
  count=0
  for i in string:
    for v in vowels:
      if i==v:
        count=count+1
  print count

Student4330

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 

REMOVEDp, 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