Score_scrabble SOLVED


#1

J'ai cette erreur. Votre fonction échoué sur tarte comme entrée car votre fonction indique une erreur "global name 'reponse' is not defined""

Mon code fonctionne pourtant bien:

score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2, 
         "f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3, 
         "l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1, 
         "r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4, 
         "x": 8, "z": 10}
         
def score_scrabble(mot):
    total=0
    for lettre in mot:
        total += score[lettre.lower()]
    return total

print score_scrabble("Zozo")

#2

Reload web browser, I mean, I don't see any mistakes.


#3

I solved it by adding this at the beginning of my code

class str(object):
     def __add__(self, other):
        return True

#4

Im happy for you :), please 'close' Thread, and goodluck coding! :smile:


#5

Same but for me (french version) :
Oups, merci de réessayer.
Votre fonction échoué sur tarte comme entrée car votre fonction indique une erreur "global name 'reponse' is not defined".

the workarround
class str(object):
def add(self, other):
return True

do not solve (it's just a hack to pass the test as OK)


#6

I also tried the following for the French version.
Answer is correct but system return alert: Oups, merci de réessayer. Votre fonction échoué sur tarte comme entrée car votre fonction indique une erreur "'int' object is not callable".

---- My code ----

score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}

mot = raw_input('Entrez votre mot :')

def score_scrabble(mot):
total = 0
for i in mot:
total += score[i.lower()]
return total

reponse = score_scrabble(mot)
print reponse


#7

It's not really solved, more a workaround :smiley:, but thanks for it !

Got the same error with

def score_scrabble(mot):
mot = mot.lower()
score_total = 0
for lettre in mot:
score_total += score[lettre]
return score_total

which never mentions any 'reponse'.
My codes may be wrong, but it's the third time a code runs on my pc but not in the exercise.
Is there a way to report bugs?

(Sorry for the code format)


#8

score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}
mot = raw_input('Entrez votre mot :')
def score_scrabble(mot):
total = 0

for i in mot:
total += score[i.lower()]
return total

print score_scrabble(mot)