元。 点击复制后,将打开C知道体验页 | 用Python代码写每天道歉三次,每次买三束花,连续十天,第五天的地二次道歉的第二束花结束程序
时间: 2023-05-30 22:04:11 浏览: 77
# -*- coding: utf-8 -*-
import time
apologize_count = 0 # 道歉次数
flower_count = 0 # 花束数量
day_count = 1 # 天数
while day_count <= 10:
if flower_count == 9 and day_count == 5 and apologize_count == 2:
print('第五天的第二次道歉的第二束花已买完,程序结束!')
break
else:
print(f'今天是第{day_count}天,已经道歉{apologize_count}次,买了{flower_count}束花。')
apologize_count += 1
flower_count += 3
if apologize_count > 2:
apologize_count = 0
day_count += 1
time.sleep(1) # 暂停1秒,模拟实际情况
print('程序结束!')