POO : TypeError et arguments
Bonsoir, j'ai un petit problème, non pas pour le langage Python en lui-même, mais plutôt pour la notion de POO que je commence peu à peu à assimiler depuis aujourd'hui.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #!/usr/bin/env python
# -*- coding: utf8 -*-
class Roulette :
def __init__(self, nb):
pass
def color(self, nb):
if nb == 0:
self.color = "green"
elif nb == 2 or nb == 4 or nb == 6 or nb == 8 or nb == 10 or nb == 11 or nb == 13 or nb == 15 or nb == 17 or nb == 20 or nb == 22 or nb == 24 or nb == 26 or nb == 28 or nb == 29 or nb == 31 or nb == 33 or nb == 35 :
self.color = "black"
else :
self.color = "red"
return self.color
pass
def parity(self, nb):
if nb % 2 == 0:
self.parity = True
else:
self.parity = False
return self.parity
pass
pass
chance = Roulette(36)
print(chance.color())
print (chance.parity()) |
Je m'attends là à voir : "red True" mais j'ai ceci à la place :
Citation:
TypeError: color() takes exactly 2 arguments (1 given)
J'envoie pourtant l'argument avec "Roulette(36)", non ?
Merci d'avance pour votre aide !