From ea1ae5114c22c5698b8a7a37ed11242b42ff3011 Mon Sep 17 00:00:00 2001 From: zbw <3075220362@qq.com> Date: Sun, 28 Sep 2025 19:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8Bzbw.py1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbw.py | 61 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/zbw.py b/zbw.py index defcd9b..f5273ae 100644 --- a/zbw.py +++ b/zbw.py @@ -1,29 +1,32 @@ -import time -from datetime import datetime - -def display_live_time(): - """ - 实时显示当前时间,每秒更新一次。 - """ - try: - while True: - # 1. 获取当前时间 - now = datetime.now() - - # 2. 格式化时间为字符串 (年-月-日 时:分:秒) - current_time_str = now.strftime("%Y-%m-%d %H:%M:%S") - - # 3. 打印时间。end='\r' 表示不换行,而是将光标移回行首,实现覆盖更新。 - # flush=True 确保立即显示在终端。 - print(f"当前时间: {current_time_str}", end="\r", flush=True) - - # 4. 暂停1秒 - time.sleep(1) - - except KeyboardInterrupt: - # 当用户按下 Ctrl+C 时,捕获 KeyboardInterrupt 异常, - # 打印一个换行和提示信息,然后优雅地退出程序。 - print("\n程序已退出。") - -if __name__ == "__main__": - display_live_time() \ No newline at end of file +ard=[] +for i in ls: + card.append((i,"红桃")) +for i in ls: + card.append((i,"黑桃")) +for i in ls: + card.append((i,"梅花")) +for i in ls: + card.append((i,"方块")) +m = int(input("请输入A抽取的序号(1-52),输入0结束:")) +a = int(input("请输入B抽取的序号(1-52),输入0结束:")) +while m!=0 and a!=0: + while a == m: + a = int(input("重复!请重新输入B抽取的序号(1-52),输入0结束:")) + random.shuffle(card) + if 1<=m<=52 and 1<=a<=52: + print("A的牌:",card[m-1][0],end="----") + print("B的牌:",card[a-1][0]) + if ls.index(card[m-1][0])ls.index(card[a-1][0]): + print("A赢了!") + elif ls.index(card[m-1][0])==ls.index(card[a-1][0]): + print("打平!") + m = int(input("请输入A抽取的序号(1-52),输入0退出:")) + a = int(input("请输入B抽取的序号(1-52),输入0结束:")) + elif 1<=m<=52 and (a<1 or a>52): + a = int(input("不存在!请重新输入B抽取的序号(1-52),输入0退出:")) + elif 1<=a<=52 and (m<1 or m>52): + m = int(input("不存在!请重新输入A抽取的序号(1-52),输入0退出:")) +print("结束!谢谢您的使用!") +print("2315304160 软工一班 臧博文") \ No newline at end of file