go语言编写的猜数字的小游戏代码随机生成一个数字,输入一个数字看是否匹对,匹配则结速,反之提示是大了还是小了转自:http://www.waylau.compackage mainimport ( "bufio" "fmt" "math/rand" "os"……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2782浏览 672个赞
python自动修改本机网关的代码#!/usr/bin/python#auto change gateway Created By mickelfengimport osimport random,reg='gateway 192.168.1.'rand=random.randint(1,3)test='……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3281浏览 2132个赞
Go语言官方带了一个工具叫cgo,可以很方便的在Go语言代码中内嵌C代码或做C和Go代码的集成。下面是一段简单的在Go中内嵌C的实验代码:package main/*#include #include void say_hello() { printf("Hello World!\n");}*/……继续阅读 » 水墨上仙 8年前 (2018-01-20) 1645浏览 2918个赞
凡是线性回溯都可以归结为右递归的形式,也即是二叉树,因此对于只要求一个解的问题,采用右递归实现的程序要比回溯法要优美的多。def Test(queen,n): '''这个就不用说了吧,就是检验第n(下标,0-7)行皇后的位置是否合理''' q=queen[n] for i in xrange……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2599浏览 2172个赞
python检查序列seq 是否含有aset 中的项# -*- coding: utf-8 -*-def containsAny(seq, aset): """ 检查序列seq 是否含有aset 中的项 """ for c in seq: if c in ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2769浏览 1152个赞
python十进制转二进制,可指定位数# convert a decimal (denary, base 10) integer to a binary string (base 2)# tested with Python24 vegaseat 6/1/2005def Denary2Binary(n): ''……继续阅读 » 水墨上仙 8年前 (2018-01-20) 1942浏览 2991个赞
在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;import xlrd def open_excel(fileName="simple.xls"): try: fileH……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2654浏览 1510个赞
用Python实现二分查找#!/usr/bin/env pythonimport sys def search2(a,m): low = 0 high = len(a) - 1 while(low <= high): mid = (low + high)/2 midval ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2821浏览 354个赞
一行代码实现python字符串反转输出import reastring = 'hello world'revchars = astring[::-1]print(revchars)输出结果dlrow olleh ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3968浏览 1364个赞
你可能已经猜到 switch 可能的形式了。case 体会自动终止,除非用 fallthrough 语句作为结尾。package mainimport ( "fmt" "runtime")func main() { fmt.Print("Go runs on ") s……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2733浏览 2802个赞
在这个练习中,将会使用 Go 的并发特性来并行执行 web 爬虫。修改 Crawl 函数来并行的抓取 URLs,并且保证不重复。package mainimport ( "fmt")type Fetcher interface { // Fetch 返回 URL 的 body 内容,并且将在这个页面上……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3283浏览 2507个赞
channel 是有类型的管道,可以用 channel 操作符 <- 对其发送或者接收值。ch <- v // 将 v 送入 channel ch。v := <-ch // 从 ch 接收,并且赋值给 v。(“箭头”就是数据流的方向。)和 map 与 slice 一样,channel 使用前必须创建:ch := make(chan……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3009浏览 782个赞
Go语言for当做while用法演示package mainimport "fmt"func main() { sum := 0 for { sum ++ if sum > 10{ break }else{ fmt.Println(sum) } }} ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3160浏览 410个赞
Go语言单个文件拷贝演示代码package mainimport "fmt"import "io"import "os"func main(){ w,err := CopyFile("filecopy.go","test.go") i……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3242浏览 1383个赞
读取源文件,去掉空行,并写到目标文件/** * Created with IntelliJ IDEA. * User: hyper-carrot * Date: 12-8-31 * Time: 下午4:04 * To change this template use File | Settings | File Templates.……继续阅读 » 水墨上仙 8年前 (2018-01-20) 3338浏览 799个赞
websockets的bufferedAmount使用范例代码// 10k max buffer size.var THRESHOLD = 10240; // Create a New WebSocket connectionvar ws = new WebSocket("ws://w3mentor.com"); ……继续阅读 » 水墨上仙 8年前 (2018-01-20) 2511浏览 2890个赞
Go语言模仿linux cat命令package mainimport ( "io" "os" "fmt" "bufio" "flag")var numberFlag = flag.Bool("n"……继续阅读 » 水墨上仙 8年前 (2018-01-20) 1622浏览 760个赞
python过滤字符串中不属于指定集合的字符的类# -*- coding: utf-8 -*-import setsclass Keeper(object): def __init__(self, keep): self.keep = sets.Set(map(ord, keep)) def __getitem……继续阅读 » 水墨上仙 8年前 (2018-01-19) 2667浏览 471个赞