马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
其实早就做出来了,但只是之前做的我自己都看不懂,现在无聊就又做了一编,望大家能多多指教 :import random
words = ["see","low","row","cow","new","car"]
word = random.choice(words)
list1 = ["?"] * len(words[0])
lives = 9
index = -1
help_turns = len(word) // 2
live_picture = u"\u2764" #设置爱心图像
score = 0
right = 0
print(list1)
print("还剩生命值:",lives * live_picture)
while lives != 0 and list1 != " ".join(word).split():
answer = input("猜一个在某个单词中出现的字母:")
if answer in " ".join(word).split()[index + 1:]: #如果猜的字母在单词中
index = word.find(answer,index + 1) #设置index + 1 作为寻找起始范围,防止遇到"see"这类重复字母单词
list1[index] = answer
right += 1
elif answer == "场外援助" and help_turns > 0: #如果用户申请场外援助并还有场外援助的机会
help_alpha = int(input("请问您要揭示第几个字母:")) - 1
list1[help_alpha] = word[help_alpha]
print("现在场外援助次数还剩{}次".format(help_turns))
help_turns -= 1
elif answer == "场外援助" and help_turns == 0: #如果用户想要申请场外援助但却已用完了机会
print("场外援助次数还剩 0 次!")
answer = input("猜一个在某个单词中出现的字母:")
while answer == "场外援助": #重复直至再次输入的不是"场外援助",因为已经没有援助的机会了
print("场外援助次数还剩 0 次!")
answer = input("猜一个在某个单词中出现的字母:")
if answer in " ".join(word).split()[index + 1:]:
index = word.find(answer,index + 1)
list1[index] = answer
right += 1
else:
print("猜错了,扣除一颗生命值!")
lives -= 1
help_turns -= 1
else: #猜的字母不在单词中
print("猜错了,扣除一颗生命值!")
lives -= 1
print(list1)
print("还剩生命值:",lives * live_picture)
score = right * len(word) * (help_turns + 1) * lives #得到用户成绩
all_score = len(word) * len(word) * (len(word) // 2 + 1) * len(word) #得到总成绩
score = score / (all_score / 100) #见下方注释,与总成绩一起变化
all_score = all_score / (all_score / 100) #将总成绩变成 100 分
if lives > 0:
print("你赢了!恭喜你在这次竞赛中获得了{}分,满分{}分!".format(score,all_score))
else:
print("你输了!正确答案是:{},恭喜你在这次竞赛中获得了{}分,满分{}分!".format(word,score,all_score))
|