[Tutor] How to make comparison work
Gregg Martinson
gregg.martinson at gmail.com
Fri Apr 11 01:27:41 CEST 2014
I have been working through a fairly simple process to teach myself python
and I am running into a problem with a comparison. Can anyone tell me
where I am going wrong?
#!/usr/bin/env python
class Team(object):
code = ""
opponents_debated=[]
wins=0
losses=0
competitors=[]
def __init__(self, code):
self.code = code
self.competitors.append(code)
#self.school_teams.append(code)
####HERE'S THE LOGIC PROBLEM
def havedebated(self, otherTeam):
print (self.code, "compares ", otherTeam, "is in",self.competitors)
if otherTeam in self.competitors:
return 1
else:
return 0
def giveCode(self):
return self.code
def debates(self,otherteam):
self.competitors.append(otherteam)
def make_team(code):
team = Team(code)
return team
#MAIN Program#
myTeamCodes = ["a", "aa", "b", "bb", "c", "cc", "d"]
# Make teams
myTeams = [] #list of teams
for x in myTeamCodes:
myteam = make_team(x)
myTeams.append(myteam)
for x in myTeams:
x.print_team()
for x in myTeams:
for y in myTeams:
affteam=x.giveCode()
negteam=y.giveCode()
print (affteam," vs. ",negteam)
#have the two teams debated?
if x.havedebated(negteam):
print("they have debated...")
continue
else:
print("DEBATE!") #NEVER HAPPENS!
x.debates(negteam)
thiscode=x.giveCode();
othercode=y.giveCode();
print(thiscode,"debates ",othercode)
--
http://about.me/greggmartinson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140410/6e06527f/attachment-0001.html>
More information about the Tutor
mailing list