From d941d6cbbcffe43c878027b1203bb3a8f9c67b95 Mon Sep 17 00:00:00 2001 From: gongjd Date: Fri, 28 Apr 2017 17:51:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=8C=9C=E6=8B=B3=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datastruct/finger_game.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 datastruct/finger_game.py diff --git a/datastruct/finger_game.py b/datastruct/finger_game.py new file mode 100644 index 0000000..2d678bf --- /dev/null +++ b/datastruct/finger_game.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +import random +while 1: + s = int(random.uniform(1, 3)) + if s == 1: + ind = "石头" + elif s == 2: + ind = "剪子" + elif s == 3: + ind = "布" + m = raw_input('输入 石头、剪子、布,输入"end"结束游戏:') + blist = ['石头', "剪子", "布"] + if (m not in blist) and (m != 'end'): + print "输入错误,请重新输入!" + elif (m not in blist) and (m == 'end'): + print "\n游戏退出中..." + break + elif m == ind : + print "电脑出了: " + ind + ",平局!" + elif (m == '石头' and ind =='剪子') or (m == '剪子' and ind =='布') or (m == '布' and ind =='石头'): + print "电脑出了: " + ind +",你赢了!" + elif (m == '石头' and ind =='布') or (m == '剪子' and ind =='石头') or (m == '布' and ind =='剪子'): + print "电脑出了: " + ind +",你输了!" \ No newline at end of file From 0d4d6d4385733d82dc5e1e9975a511f0dc71e526 Mon Sep 17 00:00:00 2001 From: gongjd Date: Wed, 3 May 2017 14:21:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=B8=B8=E6=88=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datastruct/finger_game.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/datastruct/finger_game.py b/datastruct/finger_game.py index 2d678bf..aad2310 100644 --- a/datastruct/finger_game.py +++ b/datastruct/finger_game.py @@ -3,23 +3,22 @@ import random while 1: - s = int(random.uniform(1, 3)) - if s == 1: - ind = "石头" - elif s == 2: - ind = "剪子" - elif s == 3: - ind = "布" - m = raw_input('输入 石头、剪子、布,输入"end"结束游戏:') - blist = ['石头', "剪子", "布"] + s_ = int(random.uniform(1, 3)) + s = str(s_) + m = raw_input('输入 1(石头)、2(剪子)、3(布),输入"end"结束游戏:') + alist = ["石头","剪刀","布"] + blist = ["1","2","3"] if (m not in blist) and (m != 'end'): print "输入错误,请重新输入!" elif (m not in blist) and (m == 'end'): print "\n游戏退出中..." break - elif m == ind : - print "电脑出了: " + ind + ",平局!" - elif (m == '石头' and ind =='剪子') or (m == '剪子' and ind =='布') or (m == '布' and ind =='石头'): - print "电脑出了: " + ind +",你赢了!" - elif (m == '石头' and ind =='布') or (m == '剪子' and ind =='石头') or (m == '布' and ind =='剪子'): - print "电脑出了: " + ind +",你输了!" \ No newline at end of file + elif m == s : + print "电脑出了: " + s+"("+alist[s_-1]+")"+ ",平局!" + elif (m == '1' and s =='2') or (m == '2' and s =='3') or (m == '3' and s =='1'): + print "电脑出了: " + s+"("+alist[s_-1]+")"+ ",你赢了!" + elif (m == '1' and s =='3') or (m == '2' and s =='1') or (m == '3' and s =='2'): + print "电脑出了: " + s+"("+alist[s_-1]+")"+ ",你输了!" + else : + print "m:"+m+" s:"+s + print "未知错误!" \ No newline at end of file From 7619994a37e0752e2ab25e0dcbf355a199f53369 Mon Sep 17 00:00:00 2001 From: gongjd Date: Mon, 8 May 2017 18:14:44 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- primer/2/2_2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primer/2/2_2.py b/primer/2/2_2.py index 5d71d06..349d9ae 100644 --- a/primer/2/2_2.py +++ b/primer/2/2_2.py @@ -4,6 +4,6 @@ if a != x: print "sorry you are wrong!\ninput again:" x = raw_input() -else +else : print "you are right" raw_input() From cacea338fa708d95d66f46e5990426b4e01f7893 Mon Sep 17 00:00:00 2001 From: gongjd Date: Mon, 8 May 2017 18:15:15 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mytest/SMTP.py | 34 ++++++++++++++++++++++++++++++++++ mytest/client.py | 13 +++++++++++++ mytest/server.py | 17 +++++++++++++++++ mytest/thread.py | 25 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+) create mode 100644 mytest/SMTP.py create mode 100644 mytest/client.py create mode 100644 mytest/server.py create mode 100644 mytest/thread.py diff --git a/mytest/SMTP.py b/mytest/SMTP.py new file mode 100644 index 0000000..c571599 --- /dev/null +++ b/mytest/SMTP.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +import smtplib +from email.mime.text import MIMEText +from email.utils import formataddr + +my_sender = '429240967@qq.com' # 发件人邮箱账号 +my_pass = 'xxxxxxxxxx' # 发件人邮箱密码 +my_user = '429240967@qq.com' # 收件人邮箱账号,我这边发送给自己 + + +def mail(): + ret = True + try: + msg = MIMEText('填写邮件内容', 'plain', 'utf-8') + msg['From'] = formataddr(["FromRunoob", my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 + msg['To'] = formataddr(["FK", my_user]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 + msg['Subject'] = "菜鸟教程发送邮件测试" # 邮件的主题,也可以说是标题 + + server = smtplib.SMTP("smtp.qq.com", 25) # 发件人邮箱中的SMTP服务器,端口是25 + server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱密码 + server.sendmail(my_sender, [my_user, ], msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 + server.quit() # 关闭连接 + except Exception: # 如果 try 中的语句没有执行,则会执行下面的 ret=False + ret = False + return ret + + +ret = mail() +if ret: + print("邮件发送成功") +else: + print("邮件发送失败") \ No newline at end of file diff --git a/mytest/client.py b/mytest/client.py new file mode 100644 index 0000000..5bde5ec --- /dev/null +++ b/mytest/client.py @@ -0,0 +1,13 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# 文件名:client.py + +import socket # 导入 socket 模块 + +s = socket.socket() # 创建 socket 对象 +host = socket.gethostname() # 获取本地主机名 +port = 12345 # 设置端口好 + +s.connect((host, port)) +print s.recv(1024) +s.close() \ No newline at end of file diff --git a/mytest/server.py b/mytest/server.py new file mode 100644 index 0000000..dcc3c31 --- /dev/null +++ b/mytest/server.py @@ -0,0 +1,17 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# 文件名:server.py + +import socket # 导入 socket 模块 + +s = socket.socket() # 创建 socket 对象 +host = socket.gethostname() # 获取本地主机名 +port = 12345 # 设置端口 +s.bind((host, port)) # 绑定端口 + +s.listen(5) # 等待客户端连接 +while True: + c, addr = s.accept() # 建立客户端连接。 + print '连接地址:', addr + c.send('欢迎访问菜鸟教程!') + c.close() # 关闭连接 \ No newline at end of file diff --git a/mytest/thread.py b/mytest/thread.py new file mode 100644 index 0000000..b3e1c9d --- /dev/null +++ b/mytest/thread.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +import thread +import time + + +# 为线程定义一个函数 +def print_time(threadName, delay): + count = 0 + while count < 5: + time.sleep(delay) + count += 1 + print "%s: %s" % (threadName, time.ctime(time.time())) + + +# 创建两个线程 +try: + thread.start_new_thread(print_time, ("Thread-1", 2,)) + thread.start_new_thread(print_time, ("Thread-2", 4,)) +except: + print "Error: unable to start thread" + +while 1: + pass \ No newline at end of file