I'm new to programming and especially to python and I have a compulsory project to do.
I explain: I have a list of objects (they are people), each one with characteristics, each characteristic is based on a scale from 1 to 5 (not important for understanding the problem) so I have 6 men and 6 women predefined as objects, I compare them according to their characteristics, if their characteristics are close they will be more or less a perfect match.
So my goal is to enter the names of the people I enter through an input and then my comparison function compares them. The problem is that when I manually compare by entering the names directly it works but when I insert an input, an error occurs.
I'll let you discover the code below to better understand what I'm saying because I don't know if I'm very understandable but I'd be very happy to have an answer to this problem, thank you :D
PS: Sorry for my spelling mistakes, I don't speak the language very well.
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")
Example
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
If I write 'compare(Bryan,Dita)' for exemple, It's directly the subjects, it's working but with input it's not :/
You need to store your people in dicts: