摘要: 8.1 import random def ping_pong_match(): player1_score = 0 player2_score = 0 while True: # 随机决定得分方 winner = random.choice([1, 2]) if winner == 1: play 阅读全文
posted @ 2025-05-24 14:07 kk/ 阅读(19) 评论(0) 推荐(0)
摘要: 7.1 def rewrite_py_file(file_path): try: with open(file_path, 'r', encoding='utf - 8') as f: content = f.read() new_content = "" i = 0 while i < len(c 阅读全文
posted @ 2025-05-19 12:43 kk/ 阅读(23) 评论(0) 推荐(0)
摘要: import turtle import time import datetime COLORS = { 'year': 'red', 'month': 'blue', 'day': 'green', 'hour': 'purple', 'minute': 'orange' } DIGIT_SEGM 阅读全文
posted @ 2025-05-04 15:18 kk/ 阅读(13) 评论(0) 推荐(0)
摘要: import random def genpwd(length): # 生成一个长度为length的数字密码 password = '' for _ in range(length): password += str(random.randint(0, 9)) # 生成0-9的随机数字 return 阅读全文
posted @ 2025-04-26 22:17 kk/ 阅读(28) 评论(0) 推荐(0)
摘要: 书p196程序练习题 5.1 def print_grid(width): plus = '+' dash = ' - ' pipe = '|' space = ' ' horizontal_line = plus + (dash * width + plus) * width + '\n' ver 阅读全文
posted @ 2025-04-20 12:47 kk/ 阅读(19) 评论(0) 推荐(0)
摘要: 4.1 import random def guess_number(): target = random.randint(1, 100) count = 0 while True: guess = int(input("请输入你猜的数字(1-100): ")) count += 1 if gues 阅读全文
posted @ 2025-03-31 22:32 kk/ 阅读(45) 评论(0) 推荐(0)
摘要: 3.19 import time date_str = time.strftime("%Y年%m月%d日",time.localtime()) print("当前日期:",date_str) 3.20 import time current_time = time.localtime() forma 阅读全文
posted @ 2025-03-29 15:20 kk/ 阅读(12) 评论(0) 推荐(0)
摘要: 重量计算 earth_weight = eval(input("请输入你当前的体重(kg)😊) moon_weight = earth_weight * 0.165 for year in range(1, 11): earth_weight += 0.5 moon_weight = earth_ 阅读全文
posted @ 2025-03-23 13:08 kk/ 阅读(20) 评论(0) 推荐(0)
摘要: TempConvert.py TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F','f']: C = (eval(TempStr[0:-1]) - 32)/1.8 print("转换后的温度是{:.0f}C".format(C)) elif 阅读全文
posted @ 2025-03-16 19:35 kk/ 阅读(57) 评论(0) 推荐(0)
摘要: TempConvert.py TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F','f']: C = (eval(TempStr[0:-1]) - 32)/1.8 print("转换后的温度是{:.2f}C".format(C)) elif 阅读全文
posted @ 2025-03-16 19:00 kk/ 阅读(19) 评论(0) 推荐(0)