2013-01-24 24 views
0

我是新來的蟒蛇,我只是在做這個應用的Python PROGRAME是攪亂字猜謎

import random 

# create a sequence of words to choose from 
WORDS = ("hello","goodbye","smile","evening","daytime") 

# 

# pick one word randomly from the sequence 
word = random.choice(WORDS) 

# create a variable to see if the guess is correct 
correct = word 

# create a jumbled version of the word 
jumble ="" 
while word: 
    position = random.randrange(len(word)) 
    jumble += word[position] 
    word = word[:position] + word[(position + 1):] 

# start the game 
print(\ 
""" 
     Welcome to the anagram quiz! 

    Unscramble the letters to make a word. 
(Press the enter key at the prompt to quit.) 
""") 
print ("The jumble is:", jumble) 

guess = input("\nYour guess: ") 
guess = guess.lower() 

while (guess != correct) and (guess != ""): 
    print ("Sorry, that's not it.") 
    guess = input("Your guess: ") 
    guess = guess.lower() 

if guess == correct: 
    print ("That's it! You guessed it!\n") 

print ("Thank you for playing.") 

input("\n\nPress the enter key to exit.") 

正如你可以看到最多混爲一談一個詞爲用戶猜詞是什麼,我需要能夠改善這一點,以便用戶在被卡住時得到提示,並添加一個評分系統來獎勵那些解決雜亂而不要求提示的人。

我試過幾個小時,有沒有在那裏,你能不能幫我在添加功能。

謝謝。

+1

你的具體問題是什麼? – arshajii

+0

你的提示和評分系統代碼是什麼樣的?評分可以基於時間來解決,不需要提示就可以設置獎勵... – learner

回答

2

對於提示部分:如果玩家猜錯了指定的次數,他可以選擇要求提示。該提示將與您選擇的單詞序列一起生成,並且以成對的形式出現。所以當玩家陷入困境時,你會得到一個詞語和一個暗示。

WORDS=[['hello','greeting'],['evening','sunset'],etc.] 

至於分數的部分:你可以做基於時間的得分王,在那裏他們的失分每一秒,直到他們猜測正確,或基於猜測的得分,他們在那裏失分對每個不正確的猜測。

+0

你能爲我寫這段代碼嗎?由於我試圖按照提示進行得分評分的每一次嘗試都無法正常工作,所以一整天都在努力做到這一點。感謝您的回覆! –

+1

這不是「請給我發送代碼」服務。如果你顯示的代碼實際上是你自己的,那麼編寫描述給你的代碼應該很容易。認真地說,給它一個鏡頭,如果你卡住了,然後問一個新的(詳細的)問題。 –