0

So im trying to write my code to basically make a game of even and odd and im trying to write a command with if that if the person writes pair that they get a point if the next number is pair but im not sure what to write under the if to get it to work?

I dont know what to try but all i know is that its not working?

def pigeNumero():
    if len(chiffre)>=1:
           position = random.randint(0,len(chiffre))
           lblNumero['text'] = "Le numéro est: {0}".format(chiffre[position])


    if (chiffre % 2 == 0)(reponse = Pair):
        pointT = pointT + 1
        print("Bravo! Tu as {0} point(s)".format(pointT))
    else :
       pointO = pointO + 1
       print("Désolé. L'ordi à {0} point(s)".format(pointO))

for i in range(1,99):
    chiffre.append(i)

reponse = tk.StringVar
chkbtnPair = tk.Checkbutton(fenetre)
chkbtnPair['text'] = "Pair"
chkbtnPair['width'] = "15"
chkbtnPair['variable'] = reponse
chkbtnPair['font'] = "Arial 15"
chkbtnPair.select
chkbtnPair.pack(pady=5)

chkbtnImpair = tk.Checkbutton(fenetre)
chkbtnImpair['text'] = "Impair"
chkbtnImpair['width'] = "15"
chkbtnImpair['variable'] = reponse
chkbtnImpair['font'] = "Arial 15"
chkbtnImpair.select
chkbtnImpair.pack(pady=5)
  • 3
    `if (chiffre % 2 == 0)(reponse = pair):` Can you explain in English words what you think this line does? Because what it's actually doing is comparing `chiffree % 2` to zero, then calling the resulting Boolean as a function. – Silvio Mayolo Jan 20 '23 at 15:02
  • i thought it would divide it by two and the other one is what the people picked with my two options that i have earlier – tristan tremblay Jan 20 '23 at 15:22
  • 1
    If `chiffree` is a list instead of an integer then `chiffre % 2` makes no sense. – John Coleman Jan 20 '23 at 15:22
  • @tristantremblay At the very least, you appear to have missed a boolean operator between the two, e.g. `(chiffre % 2 == 0) and (reponse == Pair)`. – chepner Jan 20 '23 at 16:04
  • do you mind explaning a bit more about what you mean – tristan tremblay Jan 20 '23 at 16:09

0 Answers0