我一直在制作一款被称为谜语游戏的游戏,它在pycharm上工作半完美,因为代码os.system("clear")
不起作用,但它在终端上有效,但有一点点一个问题,它返回错误"非ASCII"我无法理解。我该如何解决这个问题?
无论哪种方式,我尝试使代码尽可能简单,任何人都可以检查它,如果它太大,请给我一个改变重写代码的建议。
import random
import sys
import time
riddle1 = "You’re running a race and pass the person in second place. What place are you in now?"
riddle2 = "Imagine you are in a dark room. How do you get out?"
riddle3 = "David's father has three sons : Snap, Crackle and _ _ _ ?"
riddle4 = "You answer me, but I never ask you a question. What am I?"
riddle5 = "The more you take, the more you leave behind. What am I?"
riddle6 = "What comes once in a minute, twice in a moment, but never in a thousand years?"
riddle7 = "What room that ghosts can't get in?"
riddle1_Ans = "You’re in second place. You didn't pass the person in first"
riddle2_Ans = "Stop imagining"
riddle3_Ans = "David"
riddle4_Ans = "A telephone"
riddle5_Ans = "Footsteps"
riddle6_Ans = "m"
riddle7_Ans = "The living room"
riddles_lists = [riddle1, riddle2, riddle3, riddle4, riddle5, riddle6, riddle7]
random_list = random.choice(riddles_lists)
# Welcoming the user
def welcome():
print("")
print("\033[1;31;0m", " Welcome to RIDDLES")
print("\033[1;33;0m", " ")
answer = input(" Do you want to play the game?Y/N:")
if answer in ("yes", "y"):
Introductin()
else:
print("Bye....")
sys.exit()
# RESTART GAME
def restart():
print(" ")
ask = input("Do you want to Try? if you say yes the game will restart"
" if you say no there answer of the riddle will be shown:")
if ask in ("yes", "y"):
print("Restarting game.....")
time.sleep(1)
play_game()
if ask in ("no", "n"):
print("The question was:")
print(" ")
print("\033[1;32;0m", random_list)
print(" ")
time.sleep(4)
print("\033[1;35;0m", "The answer is:")
print(" ")
time.sleep(1)
print(".........")
if random_list == riddle1:
print(riddle1_Ans)
if random_list == riddle2:
print(riddle2_Ans)
if random_list == riddle3:
print(riddle3_Ans)
if random_list == riddle4:
print(riddle4_Ans)
if random_list == riddle5:
print(riddle5_Ans)
if random_list == riddle6:
print(riddle6_Ans)
if random_list == riddle7:
print(riddle7_Ans)
print(".........")
# The Game
def Introductin():
print(" ")
print("\033[1;36;0m", "Hello there, I'm Zelandini the host of the game. You will be guessing the answer of the " \
"coming riddles"
", you have 20 second to guess. Once the time ran out you have the chance to see the answer.")
print(" ")
game_start = input("Ready?Y/N:")
if game_start in ("yes", "y"):
play_game()
def play_game():
sec = 1
print(" ")
while sec != 4:
print("Game starts in", sec)
time.sleep(1)
sec += 1
if sec == 4:
Game_Start()
def Game_Start():
minutes = 1
print(" ")
print("\033[1;32;0m BEGIN!")
print("..............")
print("\033[1;32;0m ", "The riddle is", random_list)
print("..............")
while minutes != 21:
print(">>>>", minutes, "seconds")
time.sleep(1)
minutes += 1
if minutes == 21:
print(" ")
print("\033[1;34;0m", "TIMES OUT!")
break
restart()
welcome()