how would i go about using strings and splits to be able to get a certain grade from three different grades for a specific person out of three in the list. This is the list. Justin:Calculus$90:Java$85:Python$88: Taylor:Calculus$73:Java$95:Python$86: Drew:Calculus$80:Java$75:Python$94: I am currently stuck with this. The best example I can find was this.
def phonebook():
return """
Mary:893-0234:Realtor:
Fred:897-2033:Boulder crusher:
Barney:234-2342:Professional bowler:"""
def phones():
phones = phonebook()
phonelist = phones.split('\n')
newphonelist = []
for list in phonelist:
newphonelist = newphonelist + [list.split(":")]
return newphonelist
def findPhone(person):
for people in phones():
if people[0] == person:
print "Phone number for",person,"is",people[1]
as you can see. the problem with this is it only returns both the phone number and their title. what I needed to do was to return only name and grade of a class along with the class with only 2 inputs (name,subject). here is what i have so far.
def scoreList():
return"""
Justin:Calculus$90:Java$85:Python$88:
Taylor:Calculus$73:Java$95:Python$86:
Drew:Calculus$80:Java$75:Python$94:"""
def scores():
scores=scoreList()
scorelist=scores.split('\n')
newscorelist=[]
for list in scorelist:
newscorelist=newscorelist + [list.split(":")]
scores.split('$')
return newscorelist
def findScore(student,subject):
for people in scores():
for subject in scores():
if people[0]==student:
if subject[0]==subject:
print (student,"got",score,"of the course",subject[1])
and yes, I am a novice at this. I've been searching for how to do this for days now though.