程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Code written in Python to automatically generate childrens review time

編輯:Python

There are three stages for children to learn a knowledge : Preview before class + Study hard in class + Review after class

A timetable is needed for timely review after class , Like the following :

The most troublesome thing about this schedule is to manually calculate the review time every day , I calculated it manually for a period of time , It's time-consuming and error prone , The human brain is not suitable for such calculations .

This simple and repeated calculation should still be handed over to the computer .

So last night Python Wrote a code , Complete the above tasks .

The code is as follows :

# !/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime # Import the time module 
# Date calculation function 
# start_date_list For list objects , Three int Elements , It means the day, month and year respectively 
# day_step For how many days back 
# Return value end_date_list Also for list objects , Three int Elements , It means the day, month and year respectively 
def date_count(start_date_list, day_step):
year_start = start_date_list[0]
month_start = start_date_list[1]
day_start = start_date_list[2]
start_date = datetime.datetime(year_start, month_start, day_start)
end_date = start_date + datetime.timedelta(day_step)
year_end = end_date.year
month_end = end_date.month
day_end = end_date.day
end_date_list = [year_end, month_end, day_end]
return end_date_list
study_date = input(" Please enter the date ( Such as 1990-01-01):") # Enter the current date 
# study_date = '2022-06-27'
# Split the entered date string and convert it to int type 
study_date_split = study_date.split("-")
year1 = study_date_split[0]
month1 = study_date_split[1]
day1 = study_date_split[2]
year1_int = int(year1)
month1_int = int(month1)
day1_int = int(day1)
# Generate the first stage ( Review for seven days ) My review time 
date_point_1 = [year1_int, month1_int, day1_int]
date_point_2 = date_count(date_point_1, 6)
stage_1_str = '{} month {} solstice {} month {} Japan '.format(date_point_1[1], date_point_1[2], date_point_2[1], date_point_2[2])
# Generate the second stage ( Review for four weeks , Review once a week ) The first week of review 
date_point_3 = date_count(date_point_2, 1)
date_point_4 = date_count(date_point_3, 6)
stage_2_str1 = ' The first week ({} month {} solstice {} month {} Japan )'.format(date_point_3[1], date_point_3[2], date_point_4[1], date_point_4[2])
# Generate the second stage ( Review for four weeks , Review once a week ) Review time in the second week of 
date_point_5 = date_count(date_point_4, 1)
date_point_6 = date_count(date_point_5, 6)
stage_2_str2 = ' In the second week of ({} month {} solstice {} month {} Japan )'.format(date_point_5[1], date_point_5[2], date_point_6[1], date_point_6[2])
# Generate the second stage ( Review for four weeks , Review once a week ) The third week of review time 
date_point_7 = date_count(date_point_6, 1)
date_point_8 = date_count(date_point_7, 6)
stage_2_str3 = ' The third week ({} month {} solstice {} month {} Japan )'.format(date_point_7[1], date_point_7[2], date_point_8[1], date_point_8[2])
# Generate the second stage ( Review for four weeks , Review once a week ) The fourth week of review time 
date_point_9 = date_count(date_point_8, 1)
date_point_10 = date_count(date_point_9, 6)
stage_2_str4 = ' The fourth week ({} month {} solstice {} month {} Japan )'.format(date_point_9[1], date_point_9[2], date_point_10[1], date_point_10[2])
# Summarize the review time of the second stage 
stage_2_str = stage_2_str1+stage_2_str2+stage_2_str3+stage_2_str4
# Generate the third stage ( Review for five months , Review once a month ) My review time 
stage_3_day = date_point_10[2]
stage_3_months = [date_point_10[1]+1, date_point_10[1]+2, date_point_10[1]+3, date_point_10[1]+4, date_point_10[1]+5]
stage_3_str = '{0} month {5} Japan {1} month {5} Japan {2} month {5} Japan {3} month {5} Japan {4} month {5} Japan '.format(stage_3_months[0], stage_3_months[1],
stage_3_months[2], stage_3_months[3],
stage_3_months[4], stage_3_day)
# Print out all review times 
print(' The review schedule of today's Ziheng's learning content is as follows :')
# The following sentence should have used tab character (\t) As a separator ,
# But not in Pycharm Middle runtime , Output tab Character element method Excel distinguish 
# Not only does it not recognize , It also leads to too much space between each phase and each phase 
# So I had to use '#' Instead of , Just copy the generated content to txt Make another replacement in 
# hold '#' use tab Replace 
char_separate = '#'
str_all = stage_1_str+char_separate+stage_2_str+char_separate+stage_3_str
print(str_all)
# Give Way cmd Do not close windows automatically 
input('Press Enter to exit...')

The code doesn't explain , The notes above are very clear .

The operation results are as follows :




Copy the above content to Notepad++ in ,

Then on ‘#’ Make replacement :

Then paste the replaced content into Excel That's fine ~

As the copied content arrives tab tabs , therefore Excel Automatically stored in three columns .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved