混淆单词Puzz的Python程序

2024-09-29 23:17:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我是python新手,我只是在开发这个应用程序

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.")

你可以看到混淆了一个词,让用户猜测这个词是什么,我需要能够改进这一点,以便用户在遇到困难时得到提示,并添加一个评分系统,奖励那些不需要提示就解决混乱的人。在

我已经试了好几个小时了,但是没有找到地方,你能帮我添加这个功能吗。在

谢谢。在


Tags: ofthetofrominputcreatepositionit
1条回答
网友
1楼 · 发布于 2024-09-29 23:17:38

提示部分:如果玩家猜错了指定的次数,他可以选择请求提示。提示将是您生成的内容,以及要从中选择的单词序列,以成对的形式出现。所以当玩家被卡住时,你会有一句话和一个提示来表达。在

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

至于得分部分:你可以做基于时间的评分,在他们猜对之前他们每秒钟都会失分,或者基于猜测的评分,在这种情况下,他们每猜错一次都会失分。在

相关问题 更多 >

    热门问题