您的位置:首页 > 编程语言 > Python开发

【python】Word Jumble

2015-07-30 16:40 686 查看
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 !")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python word-jumble