我是编程新手,尤其是 python,我有一个必修项目要做。
我解释:我有一个对象列表(他们是人),每个对象都有特征,每个特征都基于从 1 到 5 的等级(对于理解问题并不重要)所以我有 6 个男性和 6 个女性预定义为对象,我根据他们的特点进行比较,如果他们的特点接近,他们或多或少会完美匹配。
所以我的目标是通过输入输入我输入的人的姓名,然后我的比较函数将它们进行比较。问题是,当我通过直接输入名称进行手动比较时,它可以工作,但是当我插入输入时,会发生错误。
我会让你发现下面的代码以更好地理解我在说什么,因为我不知道我是否非常容易理解,但我很高兴能得到这个问题的答案,谢谢:D
PS:抱歉我的拼写错误,我的语言不太好。
class Candidat: #Subject class (characteristics)
def __init__(self,genre,humour,physique,intelligence,projet):
self.genre=genre
self.humour=humour
self.physique=physique
self.intelligence=intelligence
self.projet=projet
def compare(Test1,Test2): #comparison function
#Match à 100% :
if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 100%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match")
#Match à 75% :
if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 75%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match1")
if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 75%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match2")
if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 75%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match3")
if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 75%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match4")
#Match à 50% :
if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match01")
if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match02")
if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match03")
if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match04")
if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match602")
if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 50%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match103")
#Match à 25% :
if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
print("Match Parfait : 25%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match001")
if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 25%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match002")
if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 25%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match003")
if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Match Parfait : 25%")
elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
print("Mauvais Match004")
例子
Bryan=Candidat("homme",4,5,3,2)
Adrien=Candidat("homme",4,3,2,3)
Marin=Candidat("homme",5,2,4,3)
Alcaraz=Candidat("homme",4,3,2,1)
Allan=Candidat("homme",4,3,2,1)
SebyDaddy=Candidat("homme",4,3,2,1)
#--------------------------------#
Anissa=Candidat("femme",0,5,2,0)
Melanie=Candidat("femme",5,3,4,3)
Dita=Candidat("femme",4,4,3,2)
LeaMary=Candidat("femme",4,3,2,1)
Maissane=Candidat("femme",4,3,2,1)
Kellyn=Candidat("femme",4,3,2,1)
Candidat=input("Homme : ")#input Man
Candidat=input("Femme : ")#input Woman
compare(Test1,Test2)#comparing
例如,如果我写“比较(Bryan,Dita)”,它直接是主题,它正在工作但输入它不是:/