在此接收错误信息"猜词#34;游戏?

时间:2018-03-06 19:20:17

标签: python

我正在创造一个"猜这个词" python中的游戏,用于编程类的介绍。单词用短划线( - )代替元音。用户应该根据提供的提示猜测单词(单词/提示一起作为并行元组)。用户得到5个猜测,如果正确猜到了这个词,则会获得一定数量的积分。然后用户可以选择继续播放和播放。累积积分,或退出。代码一直在工作,直到我添加编码来询问用户他/她是否愿意继续玩。为了让它起作用,我需要修复什么?

#Clear Screen
print("\n"*50)

import random

#Variables
keep_playing = "y"
round_score = 0
overall_score = 0
new_words = ""
vowels = "AaEeIiOoUuYy"

#Parallel tuples
while keep_playing.lower() == "y":
    guesswords = ("Japan","France","Mexico","Italy","Australia")
    guesshints = ("Sushi comes from here","Croissants come from here","Tacos come from here","Pizza comes from here","Vegemite comes from here") 

#Random
    index = random.randrange(len(guesswords))
    guesses = 5

#Replacing vowels
    for letter in guesswords[index]:
        if letter not in vowels:
            new_words += letter
        else:
            new_words += "-"

#Output        
    print(new_words.center(80, " "))
    print("Hint:",guesshints[index])

    while guesses > 0:
        input_string = "\nGuess the word! You have " + str(guesses) + " guesses remaining: "
        user_guess = input(input_string)
        if user_guess.upper() == guesswords[index].upper():
            print("YOU WIN")
            round_score = (guesses * 2)
            overall_score += round_score
            print("Your score for this round is ",round_score)
            break
        guesses -= 1

    print("Your overall score is ",overall_score)
    keep_playing = input("Would you like to keep playing? (y/n)")   

print("GAME OVER")

0 个答案:

没有答案