9/15 Does this syntax make sense to you?


#1
    total += int(score[word[i]])

I am trying to have a variable, total, take the input, “word”, at index, i; for example, “hello” should give me “h” on the first run through, and then have my code look at the dictionary, score, at index, [word[i]] (in this case, “h”). This should give me a key, 4. I’m not sure if it’s being interpreted as a string or not, so I forced it into an integer to be sure.

Then, I have the code loop through the rest of the word, summing up the values of the keys.

Is my thinking off with this part of the code?


#2

Nevermind! I see my mistake.

I’m already passing down individual letters, so score[word[i]] isn’t right. I need to be looking at the score[i] since i already represents only 1 character, so score[i] will look up each individual key for me in “word”


#3

You should rename it too

for char in 'aoeui':
    print char

for word in 'once upon a time'.split():
    print word

for person in staff:
    print person

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.