众所周知,python是一款一门简洁且强大的编程语言,用python做出的工具都非常的绝!
但我想“调出历史”,也就是用代码命令做一个“操作系统”。
系统里也都是代码命令,像DOS那样。
我想了一下,决定复原全英文的工具。
我想了一下它要有的功能……
唉,程序里见吧!
那我们上代码吧!
(因为编的太匆忙,所以系统本身没编“help”帮助命令,想加上的可以自己加)
对了,这个程序我是原创!请勿抄袭!但是复制后利用是可以的。
源代码:
import os
import random
import subprocess
import sys
import time
import tkinter as tk
import webbrowser
import webbrowser as web
from decimal import *
from tkinter import *
from tkinter import messagebox as msgbox
print('Welcome to the Roots23 system!')
print('VERSION(test number): 61zbe62t3gkq4ex2891704(23)')
def keyplus(word):
def plusoc():
wordo = word[::-1]
wordt = wordo[::-1]
return wordt
keyword = plusoc()
return keyword
def time_get():
t = time.time()
lt = time.localtime(t)
ft = time.strftime('%Y/%m/%d %H:%M:%S', lt)
emit = ft
return emit
f = time_get()
print('The time you entered the Roots23 is', f, '.')
keyw = input('Please enter password: ')
key = None
Tkey = 'abc123'
for i in range(50000):
key = keyplus(keyw)
if key == Tkey and len(key) == len(keyw):
system_cmd_list = [
'time', 'exit', 'shutdown/', 'open_Dymger', 'rename -F ', 'remove -F ', 'new_built -F -d ', 'delete -F -d ', 'GCD', 'GDLF ', 'LDFF ', 'DITPE ', 'start ', 'count', 'VerSion',
'-V', 'home'
]
while True:
input_cmd = input('*Roots23\\uic$command_\\:>>>')
if input_cmd == system_cmd_list[0]:
print(time_get())
elif input_cmd == system_cmd_list[1]:
exit()
elif input_cmd == system_cmd_list[2]:
os.system('shutdown -s -t 0')
elif input_cmd == system_cmd_list[3]:
oldstdout_gg = sys.stdout
os.system('cls')
sys.stdout = oldstdout_gg
print('Welcome to Dymger. You can obtain instructions and help through the "help<Dymger>" command.\n')
aqs = True
def helpD():
print('''\nIf you want to input and use Dymger, you need to enter "mainE{}" in the PCTS interface and type "#join-$%Dymger><;" in the PEAH interface. After activating Dymger, you also need to import it. Enter '#include<Dymger>for<mainE>' to use Dymger! The functions that Dymger can achieve include:
1. Output.
2. Input.
3. Open web page.
4. Search using Baidu.
5. Calculation.
6. Open file.
7. Display the output results of commands running in CMD.
8. Time-wait.
9. Play Game of Life.
10. Encrypt Caesar Password.
11. Create a GUI window and display label text inside.
12. Find a representation of the average level of a set of data.
13. Shutdown.
The corresponding functions are:
1. dyout << text
2. dyin >> text
3. OWP >> website <<
4. BDsch >> search Content <<
5. count >> formula <<
6. OF << file path
7. cmd << command
8. time.sw << waiting seconds
9. play << Game of Life
10. CaesarPassword.encryption << ciphertext
11. magle << text
12. aver << a set of data
13. sys.off/
After understanding these, you can easily use Dymger!\n''')
def DF():
print('\n')
nl = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
cn = random.randint(48217382734, 98127366129)
for i in range(cn):
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20
m01 = nln
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20
m02 = nln
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20 + '*'
m03 = nln
m = m01 + m02 + m03
print(m)
ts = random.uniform(0.00000000000000000000000000000018, 0.000000000000049)
time.sleep(ts)
print('\n')
def DFW():
print('\n')
nl = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
while True:
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20
m01 = nln
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20
m02 = nln
nlr_1 = random.choice(nl)
nlr_2 = random.choice(nl)
nlr_3 = random.choice(nl)
nlr_4 = random.choice(nl)
nlr_5 = random.choice(nl)
nlr_6 = random.choice(nl)
nlr_7 = random.choice(nl)
nlr_8 = random.choice(nl)
nlr_9 = random.choice(nl)
nlr_10 = random.choice(nl)
nlr_11 = random.choice(nl)
nlr_12 = random.choice(nl)
nlr_13 = random.choice(nl)
nlr_14 = random.choice(nl)
nlr_15 = random.choice(nl)
nlr_16 = random.choice(nl)
nlr_17 = random.choice(nl)
nlr_18 = random.choice(nl)
nlr_19 = random.choice(nl)
nlr_20 = random.choice(nl)
nln = nlr_1 + nlr_2 + nlr_3 + nlr_4 + nlr_5 + nlr_6 + nlr_7 + nlr_8 + nlr_9 + nlr_10 + nlr_11 + nlr_12 + nlr_13 + nlr_14 + nlr_15 + nlr_16 + nlr_17 + nlr_18 + nlr_19 + nlr_20 + '*'
m03 = nln
m = m01 + m02 + m03
print(m)
print('\n')
def web_go():
urg = sqh5_as_cs
ur = 'https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=' + urg
webbrowser.open(ur)
while aqs == True:
pcts = input('\PCTS:\>>>')
if pcts == 'mainE{}':
peah = input('\PEAH:\>>>')
if peah == '#join-$%Dymger><;':
while True:
strii = str(input('\Dymger\>>>'))
if strii == '#include<Dymger>for<mainE>':
while True:
strii = str(input('\Dymger\>>>'))
sqh1 = strii[:9]
sqh1_cs = strii[9:]
sqh2_1 = strii[:9]
sqh2_2 = strii[-3:]
sqh2_as_cs = strii[9:-3]
sqh3_1 = strii[:7]
sqh3_2 = strii[-3:]
sqh3_as_cs = strii[7:-3]
sqh4 = strii[:8]
sqh4_cs = strii[8:]
sqh5_1 = strii[:9]
sqh5_2 = strii[-3:]
sqh5_as_cs = strii[9:-3]
sqh6 = strii[:6]
sqh6_cs = strii[6:]
sqh7 = strii[:7]
sqh7_cs = strii[7:]
sqh8 = strii[:11]
sqh8_cs = strii[11:]
sqh9 = strii[:29]
sqh9_cs = strii[29:]
sqh10 = strii[:9]
sqh10_cs = strii[9:]
sqh11 = strii[:8]
sqh11_cs = strii[8:]
if sqh1 == 'dyout << ':
print(sqh1_cs)
elif sqh4 == 'dyin >> ':
ot = input(sqh4_cs)
print('<return "', ot, '">')
elif sqh11 == 'aver << ':
print(
'''The "aver" function has a bug, and the returned results may be inaccurate or have errors. Please do not refer to its return value.'''
)
time.sleep(0.5)
lstw = sqh11_cs.split(', ')
lst = list(lstw)
for i in lst:
x = float(i)
ber = 0
for i in range(len(lst)):
ber += i
num = ber / len(lst)
print(num)
elif sqh2_1 == 'count >> ' and sqh2_2 == ' <<':
def delBlank(str):
ans = ''
for e in str:
if e != ' ':
ans += e
return ans
def precede(a, b):
prior = (
('>', '>', '<', '<', '<', '>', '<', '>'),
('>', '>', '<', '<', '<', '>', '<', '>'),
('>', '>', '>', '>', '<', '>', '<', '>'),
('>', '>', '>', '>', '<', '>', '<', '>'),
('<', '<', '<', '<', '<', '=', '<', ' '),
('>', '>', '>', '>', ' ', '>', '>', '>'),
('>', '>', '>', '>', '<', '>', '>', '>'),
('<', '<', '<', '<', '<', ' ', '<', '=')
)
char2num = {
'+': 0,
'-': 1,
'*': 2,
'/': 3,
'(': 4,
')': 5,
'^': 6,
'#': 7
}
return prior[char2num[a]][char2num[b]]
def operate(a, b, operator):
if operator == '+':
ans = a + b
elif operator == '-':
ans = a - b
elif operator == '*':
ans = a * b
elif operator == '/':
if b == 0:
ans = 'VALUE ERROR! '
else:
ans = a / b
elif operator == '^':
if a == 0 and b == 0:
ans = 'VALUE ERROR! '
else:
ans = a ** b
return ans
def calc(exp):
exp += '#'
operSet = '+-*/^()#'
stackOfOperator, stackOfNum = ['#'], []
pos, ans, index, length = 0, 0, 0, len(exp)
while index < length:
e = exp[index]
if e in operSet:
topOperator = stackOfOperator.pop()
compare = precede(topOperator, e)
if compare == '>':
try:
b = stackOfNum.pop()
a = stackOfNum.pop()
except:
return 'FORMAT ERROR! '
ans = operate(a, b, topOperator)
if ans == 'VALUE ERROR! ':
return ans
else:
stackOfNum.append(ans)
elif compare == '<':
stackOfOperator.append(topOperator)
stackOfOperator.append(e)
index += 1
elif compare == '=':
index += 1
elif compare == ' ':
return 'FORMAT ERROR! '
else:
pos = index
while not exp[index] in operSet:
index += 1
temp = exp[pos:index]
last = index - 1
if '.' in temp:
while exp[last] == '0':
last -= 1
temp = exp[pos:last + 1]
try:
temp = Decimal(temp)
except:
return 'INPUT ERROR! '
stackOfNum.append(temp)
if len(stackOfNum) == 1 and stackOfOperator == []:
return stackOfNum.pop()
else:
return 'INPUT ERROR! '
if __name__ == '__main__':
exp = strii[9:-3]
getcontext().prec = 10
exp = delBlank(exp)
ans = calc(exp)
print(ans)
elif strii == 'play << Game of Life':
class Lifes:
def __init__(self, rows=36, cols=36):
self.row = rows + 2
self.col = cols + 2
self.items = [[0] * self.col for _ in range(self.row)]
self.histroy = []
self.histroySize = 30
self.running = False
self.runningSpeed = 100
def rndinit(self, rate=0.1):
self.histroy = []
for i in range(self.row):
for j in range(self.col):
rnd = random.random()
if rnd > 1 - rate:
self.items[i][j] = 1
def reproduce(self):
new = [[0] * self.col for _ in range(self.row)]
self.add_histroy()
if len(self.histroy) > self.histroySize:
self.histroy.pop(0)
for i in range(self.row):
for j in range(self.col):
if i * j == 0 or i == self.row - 1 or j == self.col - 1:
new[i][j] = 0
else:
lifes = 0
for m in range(i - 1, i + 2):
for n in range(j - 1, j + 2):
if m == i and n == j:
continue
lifes += self.items[m][n]
if self.items[i][j]:
if lifes == 2 or lifes == 3:
new[i][j] = 1
else:
new[i][j] = 0
else:
if lifes == 3:
new[i][j] = 1
for idx, narray in enumerate(new):
self.items[idx] = narray
def is_stable(self):
if len(self.histroy) < self.histroySize:
return False
arr = []
for i in self.histroy:
if i not in arr:
arr.append(i)
if len(arr) < 10:
return True
def add_histroy(self, Items=None):
arr = []
if Items == None:
Items = self.items[:]
for item in Items:
b = 0
for i, n in enumerate(item[::-1]):
b += n * 2 ** i
arr.append(b)
self.histroy.append(arr)
def drawCanvas():
global tv, rect
tv = tk.Canvas(win, width=win.winfo_width(), height=win.winfo_height())
tv.pack(side="top")
for i in range(36):
coord = 40, 40, 760, i * 20 + 40
tv.create_rectangle(coord)
coord = 40, 40, i * 20 + 40, 760
tv.create_rectangle(coord)
coord = 38, 38, 760, 760
tv.create_rectangle(coord, width=2)
coord = 39, 39, 760, 760
tv.create_rectangle(coord, width=2)
coord = 38, 38, 762, 762
tv.create_rectangle(coord, width=2)
R, XY = 8, [50 + i * 20 for i in range(36)]
rect = [[0] * 36 for _ in range(36)]
for i, x in enumerate(XY):
for j, y in enumerate(XY):
rect[i][j] = tv.create_rectangle(x - R, y - R, x + R, y + R,
tags=('imgButton1'))
tv.itemconfig(rect[i][j], fill='lightgray', outline='lightgray')
tv.tag_bind('imgButton1', '<Button-1>', on_Click)
def drawLifes():
R, XY = 8, [50 + i * 20 for i in range(36)]
if Life.running:
for i, x in enumerate(XY):
for j, y in enumerate(XY):
if Life.items[i + 1][j + 1]:
tv.itemconfig(rect[i][j], fill='green', outline='green')
else:
tv.itemconfig(rect[i][j], fill='lightgray',
outline='lightgray')
tv.update()
Life.reproduce()
if Life.is_stable():
Life.running = False
if sum(sum(Life.items, [])):
msgbox.showinfo('prompt',
'Life reproduction and annihilation enter a stable state!!!')
else:
msgbox.showinfo('prompt',
'All life is annihilated, entering a state of death!!!')
win.after(Life.runningSpeed, drawLifes)
def StartLife():
if sum(sum(Life.items, [])):
Life.histroy = []
Life.running = True
else:
msgbox.showinfo('prompt',
'Please click on the small box to fill in the life cells, or use the random function!')
def BreakLife():
Life.running = not Life.running
if Life.running:
Life.histroy.clear()
Life.add_histroy()
def RandomLife():
Life.rndinit()
Life.running = True
def ClearLife():
Life.running = False
Life.histroy = []
Life.items = [[0] * 38 for _ in range(38)]
for x in range(36):
for y in range(36):
tv.itemconfig(rect[x][y], fill='lightgray', outline='lightgray')
def btnCommand(i):
if i == 0:
return StartLife
elif i == 1:
return BreakLife
elif i == 2:
return RandomLife
elif i == 3:
return ClearLife
def on_Click(event):
x, y = (event.x - 40) // 20, (event.y - 40) // 20
if not Life.running:
if Life.items[x + 1][y + 1]:
tv.itemconfig(rect[x][y], fill='lightgray', outline='lightgray')
else:
tv.itemconfig(rect[x][y], fill='red', outline='red')
Life.items[x + 1][y + 1] = not Life.items[x + 1][y + 1]
def on_Close():
if msgbox.askokcancel('Quit', 'Do you want to quit?'):
Life.running = False
print(Copyright())
win.destroy()
def Introduce():
txt = '''Game of Life\nSurvival Law:
(1)When the current cell is in an annihilation state and there are three surviving cells around it, the cell becomes in a survival state after iteration.
(2)When the current cell is in a viable state, when there are less than 2 neighboring cells living around it, the cell becomes in an annihilated state.
(3)When the current cell is in a living state, when there are more than three living cells around it, the cell becomes annihilated.
(4)When the current cell is in a living state, when there are 2 or 3 living cells around it, the cell remains intact.'''
return txt
def Copyright():
return '\n\nproducer: Dymger Author\n\n'
if __name__ == '__main__':
win = tk.Tk()
X, Y = win.maxsize()
W, H = 1024, 800
winPos = f'{W}x{H}+{(X - W) // 2}+{(Y - H) // 2}'
win.geometry(winPos)
win.resizable(False, False)
win.title('Game of Life <- Dymger')
win.update()
drawCanvas()
Life = Lifes()
drawLifes()
tLabel = tk.Label(win, width=30, height=20, background='lightgray')
tLabel.place(x=780, y=38)
tLabel.config(text='\n\n\n'.join((Introduce(), Copyright())))
tLabel.config(justify=tk.LEFT, anchor='nw', borderwidth=10, wraplength=210)
tButton = [None] * 4
bX, bY, dY = 835, 458, 50
txt = ['Starting to evolve', 'Pause Evolution', 'Random generation',
'Empty cells']
for i in range(4):
tButton[i] = tk.Button(win, text=txt[i], command=btnCommand(i))
tButton[i].place(x=bX, y=bY + dY * i, width=120, height=40)
win.mainloop()
elif sqh3_1 == 'OWP >> ' and sqh3_2 == ' <<':
sys.path.append('libs')
a = sqh3_as_cs
webbrowser.open(a)
print('\n', webbrowser.get(), '\n')
elif sqh5_1 == 'BDsch >> ' and sqh5_2 == ' <<':
web_go()
elif sqh6 == 'OF << ':
open(sqh6_cs, 'r')
elif sqh7 == 'cmd << ' or sqh7 == 'CMD << ':
p = subprocess.Popen(sqh7_cs, shell=True, stdout=subprocess.PIPE)
print(p.stdout.read())
elif sqh8 == 'time.sw << ':
time.sleep(float(sqh8_cs))
print('\nTime waiting process ends! \n')
elif sqh9 == 'CaesarPassword.encryption << ':
st = sqh9_cs
n = int(input('\nPlease enter the key: '))
st_encrypt = ''
for letter in st:
if letter == ' ':
letter_encrypt = ' '
else:
letter_encrypt = chr((ord(letter) - ord('a') + n) % 26 + ord('a'))
st_encrypt += letter_encrypt
print('The ciphertext is: ', st_encrypt, '\n')
elif sqh10 == 'magle << ':
w = tk.Tk()
w.title('maglebox')
tk.Label(w, text=sqh10_cs).pack()
elif strii == 'sys.off/':
os.system('shutdown -s -t 0')
elif strii == 'help<Dymger>' or strii == 'help':
helpD()
elif strii == '':
continue
else:
print('\nER: Invalid function command "\033[0m', strii, '"!\n\033[0m')
else:
print('\nYou did not include Dymger, program restart!\n')
time.sleep(2.25)
oldstdout = sys.stdout
os.system('cls')
sys.stdout = oldstdout
break
elif peah == 'help<Dymger>' or peah == 'help':
helpD()
elif peah == '/':
DF()
elif peah == 'sys.off/':
os.system('shutdown -s -t 0')
else:
print('\nYour PEAH error, program exit!')
break
exit()
elif pcts == 'help<Dymger>' or pcts == 'help':
helpD()
elif pcts == '/':
DF()
elif pcts == 'sys.off/':
os.system('shutdown -s -t 0')
elif pcts == '#include<codinun>' or pcts == '\\':
time.sleep(0.018)
oldstdout_gg = sys.stdout
os.system('cls')
sys.stdout = oldstdout_gg
while True:
strii = str(input('\Dymger\>>>'))
sqh1 = strii[:9]
sqh1_cs = strii[9:]
sqh2_1 = strii[:9]
sqh2_2 = strii[-3:]
sqh2_as_cs = strii[9:-3]
sqh3_1 = strii[:7]
sqh3_2 = strii[-3:]
sqh3_as_cs = strii[7:-3]
sqh4 = strii[:8]
sqh4_cs = strii[8:]
sqh5_1 = strii[:9]
sqh5_2 = strii[-3:]
sqh5_as_cs = strii[9:-3]
sqh6 = strii[:6]
sqh6_cs = strii[6:]
sqh7 = strii[:7]
sqh7_cs = strii[7:]
sqh8 = strii[:11]
sqh8_cs = strii[11:]
sqh9 = strii[:29]
sqh9_cs = strii[29:]
sqh10 = strii[:9]
sqh10_cs = strii[9:]
sqh11 = strii[:8]
sqh11_cs = strii[8:]
if sqh1 == 'dyout << ':
print(sqh1_cs)
elif sqh4 == 'dyin >> ':
ot = input(sqh4_cs)
print('<return "', ot, '">')
elif sqh11 == 'aver << ':
print(
'''The "aver" function has a bug, and the returned results may be inaccurate or have errors. Please do not refer to its return value.'''
)
time.sleep(0.5)
lstw = sqh11_cs.split(', ')
lst = list(lstw)
for i in lst:
x = float(i)
ber = 0
for i in range(len(lst)):
ber += i
num = ber / len(lst)
print(num)
elif sqh2_1 == 'count >> ' and sqh2_2 == ' <<':
def delBlank(str):
ans = ''
for e in str:
if e != ' ':
ans += e
return ans
def precede(a, b):
prior = (
('>', '>', '<', '<', '<', '>', '<', '>'),
('>', '>', '<', '<', '<', '>', '<', '>'),
('>', '>', '>', '>', '<', '>', '<', '>'),
('>', '>', '>', '>', '<', '>', '<', '>'),
('<', '<', '<', '<', '<', '=', '<', ' '),
('>', '>', '>', '>', ' ', '>', '>', '>'),
('>', '>', '>', '>', '<', '>', '>', '>'),
('<', '<', '<', '<', '<', ' ', '<', '=')
)
char2num = {
'+': 0,
'-': 1,
'*': 2,
'/': 3,
'(': 4,
')': 5,
'^': 6,
'#': 7
}
return prior[char2num[a]][char2num[b]]
def operate(a, b, operator):
if operator == '+':
ans = a + b
elif operator == '-':
ans = a - b
elif operator == '*':
ans = a * b
elif operator == '/':
if b == 0:
ans = 'VALUE ERROR! '
else:
ans = a / b
elif operator == '^':
if a == 0 and b == 0:
ans = 'VALUE ERROR! '
else:
ans = a ** b
return ans
def calc(exp):
exp += '#'
operSet = '+-*/^()#'
stackOfOperator, stackOfNum = ['#'], []
pos, ans, index, length = 0, 0, 0, len(exp)
while index < length:
e = exp[index]
if e in operSet:
topOperator = stackOfOperator.pop()
compare = precede(topOperator, e)
if compare == '>':
try:
b = stackOfNum.pop()
a = stackOfNum.pop()
except:
return 'FORMAT ERROR! '
ans = operate(a, b, topOperator)
if ans == 'VALUE ERROR! ':
return ans
else:
stackOfNum.append(ans)
elif compare == '<':
stackOfOperator.append(topOperator)
stackOfOperator.append(e)
index += 1
elif compare == '=':
index += 1
elif compare == ' ':
return 'FORMAT ERROR! '
else:
pos = index
while not exp[index] in operSet:
index += 1
temp = exp[pos:index]
last = index - 1
if '.' in temp:
while exp[last] == '0':
last -= 1
temp = exp[pos:last + 1]
try:
temp = Decimal(temp)
except:
return 'INPUT ERROR! '
stackOfNum.append(temp)
if len(stackOfNum) == 1 and stackOfOperator == []:
return stackOfNum.pop()
else:
return 'INPUT ERROR! '
if __name__ == '__main__':
exp = strii[9:-3]
getcontext().prec = 10
exp = delBlank(exp)
ans = calc(exp)
print(ans)
elif strii == 'play << Game of Life':
class Lifes:
def __init__(self, rows=36, cols=36):
self.row = rows + 2
self.col = cols + 2
self.items = [[0] * self.col for _ in range(self.row)]
self.histroy = []
self.histroySize = 30
self.running = False
self.runningSpeed = 100
def rndinit(self, rate=0.1):
self.histroy = []
for i in range(self.row):
for j in range(self.col):
rnd = random.random()
if rnd > 1 - rate:
self.items[i][j] = 1
def reproduce(self):
new = [[0] * self.col for _ in range(self.row)]
self.add_histroy()
if len(self.histroy) > self.histroySize:
self.histroy.pop(0)
for i in range(self.row):
for j in range(self.col):
if i * j == 0 or i == self.row - 1 or j == self.col - 1:
new[i][j] = 0
else:
lifes = 0
for m in range(i - 1, i + 2):
for n in range(j - 1, j + 2):
if m == i and n == j:
continue
lifes += self.items[m][n]
if self.items[i][j]:
if lifes == 2 or lifes == 3:
new[i][j] = 1
else:
new[i][j] = 0
else:
if lifes == 3:
new[i][j] = 1
for idx, narray in enumerate(new):
self.items[idx] = narray
def is_stable(self):
if len(self.histroy) < self.histroySize:
return False
arr = []
for i in self.histroy:
if i not in arr:
arr.append(i)
if len(arr) < 10:
return True
def add_histroy(self, Items=None):
arr = []
if Items == None:
Items = self.items[:]
for item in Items:
b = 0
for i, n in enumerate(item[::-1]):
b += n * 2 ** i
arr.append(b)
self.histroy.append(arr)
def drawCanvas():
global tv, rect
tv = tk.Canvas(win, width=win.winfo_width(), height=win.winfo_height())
tv.pack(side="top")
for i in range(36):
coord = 40, 40, 760, i * 20 + 40
tv.create_rectangle(coord)
coord = 40, 40, i * 20 + 40, 760
tv.create_rectangle(coord)
coord = 38, 38, 760, 760
tv.create_rectangle(coord, width=2)
coord = 39, 39, 760, 760
tv.create_rectangle(coord, width=2)
coord = 38, 38, 762, 762
tv.create_rectangle(coord, width=2)
R, XY = 8, [50 + i * 20 for i in range(36)]
rect = [[0] * 36 for _ in range(36)]
for i, x in enumerate(XY):
for j, y in enumerate(XY):
rect[i][j] = tv.create_rectangle(x - R, y - R, x + R, y + R,
tags=('imgButton1'))
tv.itemconfig(rect[i][j], fill='lightgray', outline='lightgray')
tv.tag_bind('imgButton1', '<Button-1>', on_Click)
def drawLifes():
R, XY = 8, [50 + i * 20 for i in range(36)]
if Life.running:
for i, x in enumerate(XY):
for j, y in enumerate(XY):
if Life.items[i + 1][j + 1]:
tv.itemconfig(rect[i][j], fill='green', outline='green')
else:
tv.itemconfig(rect[i][j], fill='lightgray', outline='lightgray')
tv.update()
Life.reproduce()
if Life.is_stable():
Life.running = False
if sum(sum(Life.items, [])):
msgbox.showinfo('prompt',
'Life reproduction and annihilation enter a stable state!!!')
else:
msgbox.showinfo('prompt',
'All life is annihilated, entering a state of death!!!')
win.after(Life.runningSpeed, drawLifes)
def StartLife():
if sum(sum(Life.items, [])):
Life.histroy = []
Life.running = True
else:
msgbox.showinfo('prompt',
'Please click on the small box to fill in the life cells, or use the random function!')
def BreakLife():
Life.running = not Life.running
if Life.running:
Life.histroy.clear()
Life.add_histroy()
def RandomLife():
Life.rndinit()
Life.running = True
def ClearLife():
Life.running = False
Life.histroy = []
Life.items = [[0] * 38 for _ in range(38)]
for x in range(36):
for y in range(36):
tv.itemconfig(rect[x][y], fill='lightgray', outline='lightgray')
def btnCommand(i):
if i == 0:
return StartLife
elif i == 1:
return BreakLife
elif i == 2:
return RandomLife
elif i == 3:
return ClearLife
def on_Click(event):
x, y = (event.x - 40) // 20, (event.y - 40) // 20
if not Life.running:
if Life.items[x + 1][y + 1]:
tv.itemconfig(rect[x][y], fill='lightgray', outline='lightgray')
else:
tv.itemconfig(rect[x][y], fill='red', outline='red')
Life.items[x + 1][y + 1] = not Life.items[x + 1][y + 1]
def on_Close():
if msgbox.askokcancel('Quit', 'Do you want to quit?'):
Life.running = False
print(Copyright())
win.destroy()
def Introduce():
txt = '''Game of Life\nSurvival Law:
(1)When the current cell is in an annihilation state and there are three surviving cells around it, the cell becomes in a survival state after iteration.
(2)When the current cell is in a viable state, when there are less than 2 neighboring cells living around it, the cell becomes in an annihilated state.
(3)When the current cell is in a living state, when there are more than three living cells around it, the cell becomes annihilated.
(4)When the current cell is in a living state, when there are 2 or 3 living cells around it, the cell remains intact.'''
return txt
def Copyright():
return '\n\nproducer: Dymger Author\n\n'
if __name__ == '__main__':
win = tk.Tk()
X, Y = win.maxsize()
W, H = 1024, 800
winPos = f'{W}x{H}+{(X - W) // 2}+{(Y - H) // 2}'
win.geometry(winPos)
win.resizable(False, False)
win.title('Game of Life <- Dymger')
win.update()
drawCanvas()
Life = Lifes()
drawLifes()
tLabel = tk.Label(win, width=30, height=20, background='lightgray')
tLabel.place(x=780, y=38)
tLabel.config(text='\n\n\n'.join((Introduce(), Copyright())))
tLabel.config(justify=tk.LEFT, anchor='nw', borderwidth=10, wraplength=210)
tButton = [None] * 4
bX, bY, dY = 835, 458, 50
txt = ['Starting to evolve', 'Pause Evolution', 'Random generation', 'Empty cells']
for i in range(4):
tButton[i] = tk.Button(win, text=txt[i], command=btnCommand(i))
tButton[i].place(x=bX, y=bY + dY * i, width=120, height=40)
win.mainloop()
elif sqh3_1 == 'OWP >> ' and sqh3_2 == ' <<':
sys.path.append('libs')
a = sqh3_as_cs
webbrowser.open(a)
print('\n', webbrowser.get(), '\n')
elif sqh5_1 == 'BDsch >> ' and sqh5_2 == ' <<':
web_go()
elif sqh6 == 'OF << ':
open(sqh6_cs, 'r')
elif sqh7 == 'cmd << ' or sqh7 == 'CMD << ':
p = subprocess.Popen(sqh7_cs, shell=True, stdout=subprocess.PIPE)
print(p.stdout.read())
elif sqh8 == 'time.sw << ':
time.sleep(float(sqh8_cs))
print('\nTime waiting process ends! \n')
elif sqh9 == 'CaesarPassword.encryption << ':
st = sqh9_cs
n = int(input('\nPlease enter the key: '))
st_encrypt = ''
for letter in st:
if letter == ' ':
letter_encrypt = ' '
else:
letter_encrypt = chr((ord(letter) - ord('a') + n) % 26 + ord('a'))
st_encrypt += letter_encrypt
print('The ciphertext is: ', st_encrypt, '\n')
elif sqh10 == 'magle << ':
w = tk.Tk()
w.title('maglebox')
tk.Label(w, text=sqh10_cs).pack()
elif strii == 'sys.off/':
os.system('shutdown -s -t 0')
elif strii == 'help<Dymger>' or strii == 'help':
helpD()
elif strii == '':
continue
else:
print('\nER: Invalid function command "\033[0m', strii, '"!\n\033[0m')
elif pcts == '//':
while True:
DFW()
else:
print('\nYou have not created PCTS yet, please create it!\n')
print('\n\nWelcome to Dymger next time!\n')
time.sleep(0.018)
oldstdout_pp = sys.stdout
os.system('cls')
sys.stdout = oldstdout_pp
exit()
elif input_cmd[:10] == system_cmd_list[4]:
ot = list(input_cmd[10:].split())
target = ot[0]
new = ot[1]
os.rename(target, new)
elif input_cmd[:10] == system_cmd_list[5]:
os.remove(input_cmd[10:])
elif input_cmd[:16] == system_cmd_list[6]:
os.mkdir(input_cmd[16:])
elif input_cmd[:13] == system_cmd_list[7]:
os.rmdir(input_cmd[13:])
elif input_cmd == system_cmd_list[8]:
print(os.getcwd())
elif input_cmd[:5] == system_cmd_list[9]:
os.listdir(input_cmd[5:])
elif input_cmd[:5] == system_cmd_list[10]:
os.listdir(input_cmd[5:])
elif input_cmd[:6] == system_cmd_list[11]:
os.path.exists(input_cmd[6:])
elif input_cmd[:6] == system_cmd_list[12]:
web.open(input_cmd[6:])
elif input_cmd == system_cmd_list[13]:
arithmetic_formula = input('*Roots23\\uic$Please enter the formula_\\:>>>')
print(eval(arithmetic_formula))
elif input_cmd == system_cmd_list[14] or input_cmd == system_cmd_list[15]:
print('VERSION(test number): 61zbe62t3gkq4ex2891704(23)')
elif input_cmd == system_cmd_list[16]:
print('8-5-18-5: 14, 15')
elif input_cmd == '':
continue
else:
print('No such command!')
else:
print('Password input error, system has exited!')
time.sleep(0.75)
oldstdout_gg = sys.stdout
os.system('cls')
sys.stdout = oldstdout_gg
exit()
这段代码(程序)没有备注,强迫症患者们也不用担心!
新手复制,老手解析,高手复刻,超强者举一反三!!!
(对了,这段程序里还有些没用的东西,就是随便玩玩……)
好了,今天就到这了!
又及:这是我第一次写文章,可能有些不好,请大佬们指点!
散会!