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 Page (locked)Uploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm Exam 2 Review Fall 2004: Tracing the String Programs

Post answers, comments, and questions here!
(Back to Fall2004 Midterm 2 Review)



does this one just print the string without the "i"'s?? and all lowercase? like "georga nsttute of technology"

Not quite... look more closley at these lines:
  vowels = "aeiou"
  for i in vowels:
    loc = source.find(i)
Note that i is a variable. Greg Leo


ahhh,....so would it get rid of all the vowels??
and all lower case as well.. "grg nsttt f tchnlgy"

Will it get rid of all the vowels, or just some? If some, which ones specifically? This also depends on whether you are referring to program a. or b. Kelly Lyons

what does this mean?
    
if loc <> -1:
  source = source[:loc]+source[loc+1:]

Reason through it. What does it mean for a number to be greater than or less than a -1? Why would the method find return a -1? As for the second line, remember that, for example... string[0:4] would return the 0th 1st 2nd and 3rd characters of a string but not the 4th. Just like range, JES stops before the last number. source[:loc] is basicly like saying "Give me everything up to but not including the "loc" position of source. Greg Leo


Ok this is what i understand.....String4 takes out the first "a","e","i","o", and "u" in the string and makes all caps lower case. String5 takes out all the vowels and makes all cap lower case. But i don't quite understand how. We've (at least I've) never seen any lines like
if loc <> -1:
source = source[:loc]+source[loc+1:]
before.
That's correct, but notice that the string is first made lower case and then the vowels are replaced. Why is this necessary? Greg Leo

it's necessary b/c the I in Institute is capital at first

can someone please explain to me what [loc+1:] means? I know what [:loc] means, by the way, but not the former one.

ok I get it now.

supposing that string4() does only take out the first instance of any vowel... what kind of program would you write to take out all the vowels?


what an aggravating way to write a test problem. You could have used a variable other than "i" you know!



Link to this Page