By dolphin,20150730
Title :
改进Word Jumble,给各个单词加上一个提示。让玩家在遇到困难时能够看到提示。添加一个记分系统,对那些不用提示就把问题解决掉的玩家进行奖励。
Code:
# Word Jumble # # Computer random chosse a word, and disturb it # The player must guess the word. import random WORDS = ("python", "jumble", "easy", "difficult", "elephant", "iphone", "Dolphin") word = random.choice(WORDS) correct = word score = 0 tips = 0 # Creat a disturb word jumble = "" while word: position = random.randrange(len(word)) jumble += word[position] word = word[:position] + word[(position + 1 ):] # Play game print( """ Welcome to Word Jumble ! Unscramble the letters to make a word. (Press the enter key at the prompt to quit .) """) print("\nThe jumble is : ",jumble) print("\n Press h to get the tips.") # Get answer guess = input("\n Your guess:") # Get Tips while guess != correct and guess != "": if guess == ‘h‘: if correct == ‘python‘: print("A computer langue !") elif correct == ‘jumble‘: print("A word puzzle with a clue.") elif correct == ‘easy‘: print("Opposite word is difficult !") elif correct == ‘difficult‘: print("Opposite word is easy !") elif correct == ‘elephant‘: print("A very large animal with a long, flexible nose.") elif correct == ‘iphone‘: print("A mobile phone.") else : print("It is me ") guess = input("Guess again: ") tips = 1 else: print("Sorry , that is not it.") guess = input("Guess again: ") # Get Score if tips == 1 : score = 50; if tips == 0 : score = 100; # result if guess == correct: print("\nYeah! That‘s it ! You guessed it !\n") print("Your score is ",score) print("\nThanks for playing ! ") input("\n\nPress the enter key to exit !")
本文出自 “西伯利亚狼026” 博客,请务必保留此出处http://1429223.blog.51cto.com/1419223/1680191
原文地址:http://1429223.blog.51cto.com/1419223/1680191