scores = {"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} menu = {1: "Tally the value of a word", 2: "Change the value of a letter", 3: "Exit"} def gameplay(): menu_module() def menu_module(): print "-----------Scrabble Menu-----------" for i in menu: print i, menu[i] print '%s' %" " * 10 try: choice = int(raw_input("What would you like to do?")) if choice == 1: get_score_module() elif choice == 2: change_letter_module() else: print '%s' %" " * 10 print "Thanks for using the Scrabble Menu!" return except: print "Please enter a valid menu number." return_to_menu_module() def return_to_menu_module(): print '%s' %" " * 10 to_menu = raw_input("Would you like to return to the menu(y/n)?") if to_menu == 'y': print '%s' %" " * 10 menu_module() elif to_menu == 'n': print '%s' %" " * 10 print "Thanks for using the Scrabble Menu!" else: print "Please enter y or n." def change_letter_module(): print '%s' %" " * 10 game_on = raw_input("Would you like to change a letter's value(y/n)?") if game_on == "y": update_scores() return_to_menu_module() elif game_on == 'n': return_to_menu_module() else: print "Please enter y or n." gameplay() def update_scores(): print '%s' %" " * 10 letter = raw_input("What letter are you changing?") lower_letter = letter.lower() value = int(raw_input("What is %s's new value?" % lower_letter)) scores[letter] = value print "New scores:", scores def get_score_module(): print '%s' %" " * 10 check_word_go = raw_input("Would you like to get the score value of a word(y/n)?") if check_word_go == "y": print '%s' %" " * 10 get_word() return_to_menu_module() elif check_word_go == "n": return_to_menu_module() else: print "Please enter y or n." get_score_module() def get_word(): check_word = raw_input("What is your word?") scrabble_score(check_word) def scrabble_score(word): lower_word = word.lower() total = 0 for char in lower_word: for key in scores: if char == key: total += scores[key] print total return total gameplay()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question