bjtitus (owner)

Revisions

gist: 205540 Download_button fork
public
Description:
Some code to play around with Python
Public Clone URL: git://gist.github.com/205540.git
Embed All Files: show embed
Python #
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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()