摘要: P301 8.1 import random def ping_pong_match(): player1_score = 0 player2_score = 0 while True: # 随机决定得分方 winner = random.choice([1, 2]) if winner == 1: 阅读全文
posted @ 2025-05-25 17:53 Neflibata。 阅读(26) 评论(0) 推荐(0)
摘要: P264 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 < 阅读全文
posted @ 2025-05-17 21:08 Neflibata。 阅读(46) 评论(0) 推荐(0)
摘要: import decimal import tqdm def calculate_pi(iterations): decimal.getcontext().prec = iterations + 2 # 设置精度 pi = decimal.Decimal(0) for n in tqdm.tqdm( 阅读全文
posted @ 2025-04-26 20:28 Neflibata。 阅读(14) 评论(0) 推荐(0)
摘要: P196 5.1 def print_grid(width): plus = '+' dash = ' - ' pipe = '|' space = ' ' horizontal_line = plus + (dash * width + plus) * width + '\n' vertical_ 阅读全文
posted @ 2025-04-20 16:17 Neflibata。 阅读(20) 评论(0) 推荐(0)
摘要: 4.1 target = 425 guess = 0 count = 0 print("猜数字游戏(1-1000)") print("我已经想好了一个1-1000之间的数字,看你能猜几次猜中!") while guess != target: guess = int(input('请输入一个猜测的整 阅读全文
posted @ 2025-04-04 15:51 Neflibata。 阅读(41) 评论(0) 推荐(0)
摘要: P124 3.19 import time current_time = time.strftime("%Y-%m-%d", time.localtime()) print(current_time) 3.20 import time date1 = time.strftime("%Y-%m-%d" 阅读全文
posted @ 2025-03-29 15:49 Neflibata。 阅读(16) 评论(0) 推荐(0)
摘要: 1.重量计算 initial_weight = 60 yearly_gain = 0.5 moon_factor = 0.165 for year in range(1, 11): earth_weight = initial_weight + yearly_gain * year moon_wei 阅读全文
posted @ 2025-03-23 16:20 Neflibata。 阅读(38) 评论(0) 推荐(0)
摘要: 2.1 TempStr = eval('input("请输入带有符号的温度值:")') if TempStr[-1] in ['F', 'f']: C = (eval(TempStr[0:-1]) - 32)/ 1.8 print("转换后的温度是{:.0f}C".format(C)) elif T 阅读全文
posted @ 2025-03-16 19:40 Neflibata。 阅读(12) 评论(0) 推荐(0)
摘要: TempConvert.py TempStr = input("请输入带有符号的温度值:") if TempStr[-1] in ['F','f']: C = (eval(TempStr[0:-1]) - 32)/1.8 print("转换后的温度是C{:.2f}".format(C)) elif 阅读全文
posted @ 2025-03-16 13:27 Neflibata。 阅读(15) 评论(0) 推荐(0)
摘要: str1 = input("请输入一个人的名字:") str2 = input("请输入一个国家名字:") print("世界这么大,{}想去{}看看 .".format(str1,str2)) n = input("请输入整数N:") sum = 0 for i in range(int(n)): 阅读全文
posted @ 2025-03-09 13:49 Neflibata。 阅读(23) 评论(0) 推荐(0)