【python日常学习】猜谜小游戏
刚刚学完while语法,瞎编了个猜谜小程序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 +=1
guess = input("Enter guess:")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("猜测3次机会已用尽,你输了!!")
else:
print("恭喜你,你猜对了!!")
优化后可以自己输入想要猜的词,提示等,但是目前感觉输入提示词的时候过于麻烦,还在简化
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 +=1
guess = input("Enter guess:")
guess_count += 1
else:
out_of_guesses = True
if out_of_guesses:
print("猜测3次机会已用尽,你输了!!")
else:
print("恭喜你,你猜对了!!")
输入不是汉字,又不报错,这段代码都没。必须要输入汉字或英文的代码,你没写 额,有点迷,前面不管输入了什么,最后一个输入邓超就赢了...... 锋逸520 发表于 2020-7-29 10:22
额,有点迷,前面不管输入了什么,最后一个输入邓超就赢了......
就是有三次机会猜,每次都会给一个提示词,猜对就赢了,三次都错就输了 来论坛看了这么多帖子,终于找到一个我能看懂的代码了;www
一起加油 继续加油 学习一下,支持分享
页:
[1]