Skip to content

Instantly share code, notes, and snippets.

@bjtitus
Created October 8, 2009 23:47
Show Gist options
  • Save bjtitus/205540 to your computer and use it in GitHub Desktop.
Save bjtitus/205540 to your computer and use it in GitHub Desktop.
Some code to play around with Python
import sys
import getopt
def main():
""" print ind(40, [ 55, 77, 42, 12, 42, 100 ])
print ind(42, range(0,100))
print ind('hi', [ 'hello', 42, True ])
print ind('hi', [ 'well', 'hi', 'there' ])
print ind('i', 'team')
print ind(' ', 'outer exploration')
"""
print "input your word:"
print scrabbleScore( raw_input())
"""def ind(e, L): #this is the way it should be done
try:
value = L.index(e) #this index function searches for the item
except ValueError:
return "Value wasn't in list" #catches the error and prints a readable message
else:
return e, "occurs at index", value #prints a readable index line
"""
def ind(e, L): #the way you are probably supposed to do it.
i = 0 #sets up a counter
for item in L:
if item == e:
break #leaves for loop if item is found
else:
i=i+1 #increases if item isn't found
print i #prints the index number
def letterScore( let ):
scrabbleLetters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
scrabbleScores = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]
for letter in scrabbleLetters:
if letter in let:
return scrabbleScores[scrabbleLetters.index(letter)]
def scrabbleScore( S ):
finalScore = 0
for letter in S:
finalScore += letterScore(letter)
return finalScore
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment