'''ABCD * 9 = DCBA 通过计算机的方法,给我们计算出 A= ? B = ? C = ? D =? A; 1-9 B: 1-9 C: 1-9 D; 1-9 A != B != C != D '''例子:class CountNumber(object): '''ABCD * 9 = DCBA 通过计算机的方法,给我们计算出 A= ? B = ? C = ? D =? A; 1-9 B: 1-9 C: 1-9 D; 1-9 A != B != C != D ''' def __init__(self): print("ABCD * 9 = DCBA; A !=B !=C !=D") def numAdbcd(self): for A in range(1,10): for B in range(0,10): for C in range(0,10): for D in range(0,10): if (A*1000 + B*100 + C*10 + D) * 9 == (D*1000+C*100+B*10+A): print("{0}{1}{2}{3} *9 = {4}{5}{6}{7}".format(A,B,C,D,D,C,B,A)) print("A = {0}, B = {1}, C = {2}, D = {3}".format(A, B, C, D))def main(): countNumber = CountNumber() countNumber.numAdbcd()if __name__ == '__main__': main()
#!/usr/bin/env python# -*- coding:utf-8 -*-# @time: 2018/1/7 16:10# Author: caicai# @File: demon3.py'''九宫格'''class NinePaper(object): def __init__(self): print(''' _____________ |_A_|_B_|_C_| |_D_|_E_|_F_| |_G_|_H_|_I_| A, B, C, D, E, F, G, H, I 必须是1-9数字,且不能重复 所有的行,列,对角线的和都为15 ''') self.numbers = list() for i in range(1,10): self.numbers.append(i) print("number = {0}".format(self.numbers)) def run(self): for A in range(1,10): l1 = list() l1 += self.numbers l1.remove(A) for B in l1: l2 = list() l2 += l1 l2.remove(B) for C in l2: l3 = list() l3 += l2 l3.remove(C) for D in l3: l4 = list() l4 += l3 l4.remove(D) for E in l4: l5 = list() l5 += l4 l5.remove(E) for F in l5: l6 = list() l6 += l5 l6.remove(F) for G in l6: l7 = list() l7 += l6 l7.remove(G) for H in l7: l8 = list() l8 += l7 l8.remove(H) for I in l8: if A + B + C == D + E + F == G + H + I == A + D + G == B + E + H == C + F + I == A + E + I == C + E + G == 15: print(''' _____________ |_{0}_|_{1}_|_{2}_| |_{3}_|_{4}_|_{5}_| |_{6}_|_{7}_|_{8}_| '''.format(A, B, C, D, E, F, G, H, I))def main(): ninePaper = NinePaper() ninePaper.run()if __name__ == '__main__': main()
去一个passwd文件按序号大小进行排序写入新的字典passwd文件root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologinsystemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologinsystemd-network:x:192:192:systemd Network Management:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:998:996:User for polkitd:/:/sbin/nologincolord:x:997:995:User for colord:/var/lib/colord:/sbin/nologinabrt:x:173:173::/etc/abrt:/sbin/nologinunbound:x:996:994:Unbound DNS resolver:/etc/unbound:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologinlibstoragemgmt:x:995:993:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologinrpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologinusbmuxd:x:113:113:usbmuxd user:/:/sbin/nologinsaslauth:x:994:76:Saslauthd user:/run/saslauthd:/sbin/nologingeoclue:x:993:991:User for geoclue:/var/lib/geoclue:/sbin/nologinsetroubleshoot:x:992:989::/var/lib/setroubleshoot:/sbin/nologinrtkit:x:172:172:RealtimeKit:/proc:/sbin/nologinmysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologinqemu:x:107:107:qemu user:/:/sbin/nologinradvd:x:75:75:radvd user:/:/sbin/nologinchrony:x:991:988::/var/lib/chrony:/sbin/nologinrpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologinnfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologinpulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:/sbin/nologingdm:x:42:42::/var/lib/gdm:/sbin/nologingnome-initial-setup:x:990:985::/run/gnome-initial-setup/:/sbin/nologinavahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinntp:x:38:38::/etc/ntp:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologintcpdump:x:72:72::/:/sbin/nologinosadmin:x:1000:1000:osadmin:/home/osadmin:/bin/bashmysql-proxy:x:989:984:MySQL-Proxy user:/:/sbin/nologinwxp:x:1001:1001::/home/wxp:/bin/bashnginx:x:988:983:Nginx web server:/var/lib/nginx:/sbin/nologinuwsgi:x:987:982:uWSGI daemon user:/run/uwsgi:/sbin/nologinimport codecsimport osclass SortPasswd(object): def __init__(self): self.passwd = "passwd" self.newpasswd = "newPasswd" self.contextList = list() if not os.path.exists(self.passwd): print("please download passwd from linux.") exit(1) print("sort file is :{0}".format(self.passwd)) print("sorted file is :{0}".format(self.newpasswd)) def getContextList(self): with codecs.open("passwd") as fr: self.contextList += sorted(fr.readlines(), key=lambda line:int(line.split(":")[2]), reverse=False) print(self.contextList) def writeContextList(self): with codecs.open("new_passwd", "w") as fw: fw.writelines(self.contextList)def main(): sortpasswd = SortPasswd() sortpasswd.getContextList() sortpasswd.writeContextList()if __name__ == '__main__': main()