 |  |

 |
 |  |  |
 | Welcome to CS1315. Click on the python to add comments.
|  |
 |  |  |
|
This page removed for FERPA compliance
|
        |
Midterm Exam 2 Review Fall 2004: Find the First from the Last
Post answers, comments, and questions here!
(Back to Fall2004 Midterm 2 Review)
nope
def countAs():
string="abccbbaa"
print string
count(a)
on page 240 of text– count(something) is the clue.. but I don't know how to get it to count the a's
thanks bunches
oops- wrong place to add the question— sorry
def findFirstREMOVEDe(string, name):
new=string.split()
index=0
for n in new[:]:
if n<>name:
index=index+1
if n==name:
print new[int(index-1):int(index)]
| Getting there. The split() function reqires input. What do you think you would want to split on to separate all the words? Also, your function will look through all the names. What if one person's first name is the same as someone else's last name? So you only want to search through the last names. REMOVEDw do you search only every other item in a list (hint range)? Keep working on it. Student1594 |
def findFirstREMOVEDe(string,lastname):
names=string.split(" ")
for names in range(0,len(names),2):
place=1
if names == lastname:
firstname= place-1
print firstname
place=place+2
print names[firstname]
why doesn't this work?
wouldn't 0 in the range function be the first term?
def findFirstREMOVEDe(string,lastname):
names=string.split(" ")
for index in range(1,len(names),2):
if lastname == names[index]:
print names[index - 1]
that works....yay!
Link to this Page