Python教程
Python教程:包含了所有代写案例以及部分答案
-
python根据出生日期计算年龄的代码,运行后会提醒用户输出出生的年月日,然后输出年龄,可以改写为一个通用函数 from time import * #a function to find your age def age(): print "Enter Your Date of Birth" d=input("Day:") m=input("Month:") y=input("Year:") #get the cu … 继续阅读“python根据出生日期计算年龄的代码”
:
-
# -*- coding: utf-8 -*- # 原题:一个老师从2到9中取两个数字,给甲说了和,给乙说了积, # 甲说我不知道,乙说我也不知道,甲说你不知道那我就知道了, # 乙说你知道了那我也知道了 # 这两个数分别是多少? # ======================================================== # 为了方便表示,记两个数字的组合为字符串i&j,如2&3这种格式 # 以下是工具函数 # ============= … 继续阅读“python 解决把两个数字的和、积分别告诉两个人猜两个数字组合的问题”
:
-
#!/usr/bin/python ”’ ”’ import gtk.gdk import gtk import glib class MyRect(): def __init__(self, x = 0, y = 0, w = 0, h = 0): self.x = x self.y = y self.w = w self.h = h def __init__(self, x, y): self.x = min(int(x.x), int(y.x)) self.y = min(int(x. … 继续阅读“python linux下python抓屏小程序”
:
-
Python动态生成中文验证码“`python –– coding: utf-8 –– import Image,ImageDraw,ImageFont import random import math, string class RandomChar(): “””用于随机生成汉字””” @staticmethod def Unicode(): val = ran … 继续阅读“Python动态生成中文验证码”
:
-
python可以通过tarfile模块压缩和解压.tar.bz2包 #压缩文件夹为 .tar.bz2 import tarfile import bz2 archive = tarfile.open(‘myarchive.tar.bz2′,’w:bz2′) archive.debug = 1 # Display the files beeing compressed. archive.add(r’d:\myfiles’) # d:\myfiles contains the files to co … 继续阅读“python压缩和读取.tar.bz2格式的压缩包”
:
-
#python求txt文件中所有Z后面数字的最小值和最大值 #依山居 19:04 2015/11/7 #题目来源: http://www.bathome.net/thread-38027-1-1.html zl=[] with open("a.txt") as f: for l in f: txtline=l.rsplit() for ll in txtline: #print(ll) if ll[0]=="Z": x=float(ll[1:]) zl.a … 继续阅读“python求txt文件中所有Z后面数字的最小值和最大值”
:
-
def quickSort(arg): if(arg==[]): return [] return quickSort([i for i in arg[1:] if i<=arg[0]])+[arg[0]]+quickSort([i for i in arg[1:] if i>arg[0]]) print quickSort([12,14,25,23,2,17,13,25,34,777]) 超级"简短"的python实现的快速排序。我很喜欢这个代码,因为它很纯,很 … 继续阅读“python 快速排序python实现。”
:
-
def get_appsys_by_no(self, no): o_type = self.order_type(no) table_name = "t_order_" + o_type.lower() #: result = db.session.execute("SELECT * FROM %s where no = ‘%s’" %(table_name, no)) result = db.session.execute("SELECT * … 继续阅读“python flask-sqlalchemy”
:
-
#coding=utf-8 import socket #加载socket模块 from time import ctime #加载time模块ctime类 HOST = ” #设置主机IP,为空则表示本机上所有的网卡ip。 PORT = 3300 #设置端口号 BUSIZ = 1024 #设置数据缓冲区,1KB ADDR = (HOST, PORT) def closeTCnt(): # TCntSock.close() print "Session closing.." … 继续阅读“Python 实现半双工聊天器”
: