def get_score(word):
    '''(str) -> int

    Return the point value the word earns.

    Word length: < 3: 0 points
                 6-9: 1 point per character in word
                 7-11: 2 points per character in word
                 10+: 3 points per character in word

    >>> word_score('DRUDGERY')
    16
    '''

    I have this homework I want some help ,to guide me from where should I begin 
    this my attempt
    s=0
    if len(word) in range (6,10)------for  the second condition
    for i in range (len(word)):
    s=s+i
    but it didnot work correctly any help  please

In the future, please let give more information about how the program is failing, otherwise we won't have enough to go by.

As it happens, the answer is quite simple: the function doesn't return a value. Try adding return s at the end of the function and it should work correctly.

def <font style='color:black; background-color:Lime;'>word_score</font>(word):
    '''(<font style='color:black; background-color:Lime;'>str</font>) -> int

    Return the point value the word earns.

    Word length: < 3: 0 points
                 6-9: 1 point per character in word
                 7-11: 2 points per character in word
                 10+: 3 points per character in word

    >>> <font style='color:black; background-color:Lime;'>word_score</font>('DRUDGERY')
    16
    '''
    <font style='color:black; background-color:Lime;'>s=</font>0
    if <font style='color:black; background-color:Lime;'>len</font>(word) in range (6,10):
        for i in range (<font style='color:black; background-color:Lime;'>len</font>(word)):
            s += i
    return s

if <font style='color:black; background-color:Lime;'>__name__</font> == "<font style='color:black; background-color:Lime;'>__main__</font>":
    print(<font style='color:black; background-color:Lime;'>word_score</font>('DRUDGERY'))

I ran this and got a score of 28 for the word DRUDGERY. I know it isn't the correct score, but it should at least get you started.

BTW, the score ranges as given don't make much sense; I suspect that they should be

    Word length: < 3: 0 points
                 3-6: 1 point per character in word
                 7-10: 2 points per character in word
                 11+: 3 points per character in word

Otherwise, you have overlapping score ranges, which would be problematic - not to mention a gap between 3 and 6.

define get_score(with a string argument):
    length = len(string)
    score = 0
    if length < 3:
        score = 0
    elif score > 6:
        score = length multiplied by 1
    elif other condition:
        apply other rules to score
    ...
    return score

Erratum :)

line 6: elif length > 6:

Like Schol-R-LEA (Joseph Osako) pointed out the rukes have to be

'''
Let's assume the rules are as follows
Word length: < 3: 0 points
             3-6: 1 point per character in word
             7-10: 2 points per character in word
             11+: 3 points per character in word
'''

for you to get the correct score.
The code boils down to a series of
if
elif
else
statements

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.