刚刚学完while语法,瞎编了个猜谜小程序
[Python] 纯文本查看 复制代码 secret_word = "邓超"
guess_tips = ["中国男明星","导演","分手大师"]
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
i = 0
print("猜测机会共3次!")
while guess != secret_word and not(out_of_guesses):
if guess_count < guess_limit:
print(guess_tips[i])
i +=1
guess = input("Enter guess:")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("猜测3次机会已用尽,你输了!!")
else:
print("恭喜你,你猜对了!!")
优化后可以自己输入想要猜的词,提示等,但是目前感觉输入提示词的时候过于麻烦,还在简化
[Python] 纯文本查看 复制代码 secret_word = input("请输入想要对方猜的词:")
guess_tips = eval(input("请输入关键词:"))
for a in range(10):
print("\n")
guess = ""
guess_count = 0
guess_limit = 3
out_of_guesses = False
m = 0
print("猜测机会共3次!")
while guess != secret_word and not(out_of_guesses):
if guess_count < guess_limit:
print(guess_tips[m])
m +=1
guess = input("Enter guess:")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("猜测3次机会已用尽,你输了!!")
else:
print("恭喜你,你猜对了!!")
|