这里给出的是一个大概程序
name = input("请输入你的姓名:")
print("开始抽奖")
Name1 = ['****']
Name = []
Name.append(name)
with open('./name.txt', 'a+', encoding="utf-8") as fp:
fp.writelines(name + '\n')
def tj(name):
name_number = 0
with open('./name.txt', 'r', encoding="utf-8") as fp:
Name_yz = fp.read().splitlines()
for i in Name_yz:
if i == name:
name_number += 1
if name_number > 3:
return True
else:
return False
import random
def main():
judge = random.randint(1,110)
judge_yz = random.randint(1,110)
if (judge >= 80 and tj(name) and name in Name1) or judge == judge_yz:
print("恭喜你中了一等奖!")
elif (judge >= 80 and tj(name)) or (name in Name1 and tj(name)):
print("恭喜你中了二等奖!")
elif judge >= 80 or tj(name) or name in Name1 :
print("恭喜你中三等奖!")
else:
print("太遗憾了,还差一点就中奖了")
if __name__=="__main__":
main()
如有问题,欢迎在评论区提问。