This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stem = "甲乙丙丁戊己庚辛壬癸" | |
branch = "子丑寅卯辰巳午未申酉戌亥" | |
print(*(stem[i % 10] + branch[i % 12] for i in range(60))) | |
print([stem[i % 10] + branch[i % 12] for i in range(60)]) | |
print({i + 1: stem[i % 10] + branch[i % 12] for i in range(60)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import json | |
with open("stem_branch.json", "r") as f: | |
a = json.load(f) | |
fieldnames = ['year', '干支'] | |
with open("干支.csv", "w", newline='') as csvfile: | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames) | |
writer.writeheader() | |
for row in a: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def stem_branch(n): | |
stem = "甲乙丙丁戊己庚辛壬癸" | |
branch = "子丑寅卯辰巳午未申酉戌亥" | |
return stem[(n - 4) % 10] + branch[(n - 4) % 12] | |
d = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
import tkinter.messagebox | |
root = tk.Tk() | |
label=tk.Label(root, text="请输入年份:") | |
label.pack(side="left") | |
input=tk.Entry(root) | |
input.pack(side="left") | |
def stem_branch(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(1, 10): | |
for j in range(1, i+1): | |
print('{}x{}={}'.format(j, i, i*j), end='\t') | |
print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stem = "甲乙丙丁戊己庚辛壬癸" | |
branch = "子丑寅卯辰巳午未申酉戌亥" | |
while True: | |
try: | |
y = int(input("请输入年份:")) | |
print(f"{y}年是{stem[(y - 4) % 10]}{branch[(y - 4) % 12]}年") | |
break | |
except ValueError: | |
print("请输入年份数字!") | |
continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
# 天干(celestial stem) | |
stem = "甲乙丙丁戊己庚辛壬癸" | |
# 地支(terrestrial branch) | |
branch = "子丑寅卯辰巳午未申酉戌亥" | |
# 最小公倍数(least common multiple, LCM) | |
lcm = math.lcm(len(stem), len(branch)) | |
# 干支 | |
for i in range(lcm): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fibonacci <- function(n) { | |
if (n <= 1) | |
return(n) | |
else | |
return(fibonacci(n - 1) + fibonacci(n - 2)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacci(n): | |
if n <= 1: | |
return n | |
else: | |
return fibonacci(n - 1) + fibonacci(n - 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
import math | |
math.factorial | |
''' | |
def factorial(n): | |
if n <= 1: | |
return 1 | |
else: | |
return n * factorial(n - 1) |