目录
python安装
2.打印0-100,遇到19的时候跳出循环
3.只打印90以内的奇数
4.对发送邮件代码进行修改,换成自己的邮箱并截图保存。
5.对指导书中海龟画图和TCP/UDP的案例进行学习并运行结果。
python小项目
(1条消息) python环境安装问题_韶光不负的博客-CSDN博客
(1条消息) 小白安装pyCharm,python(python第三方安装工具pyCharm详细安装)_韶光不负的博客-CSDN博客
1,
def index_str(L,str):
for i in L:
for l in i :
if(l == str):
return l
if __name__ == '__main__':
L = [
['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa']
]
# 方法一
for i in L:
for l in i :
if(l == 'Apple'):
print(l)
elif(l == 'Python'):
print(l)
elif(l =='Lisa'):
print(l)
# 方法二
l = len(L)
str = len(L[0])
for i in range(l):
for j in range(str):
# print(L[i][j])
if(i==0 and j== 0 ):
print(L[i][j])
elif(i==1 and j== 1 ):
print(L[i][j])
elif (i == 2 and j == 2):
print(L[i][j])
#方法三
s1=index_str(L,'Apple')
print(s1)
s2 = index_str(L, 'Python')
print(s2)
s3 = index_str(L, 'Lisa')
print(s3)
if __name__ == '__main__':
num = 0 ;
while(num < 100):
print(num)
num+=1
if(num >= 20):
break;
def odd_number(n):
if( n % 2 != 0):
return n
# 不能num%2 == 0 奇数
if __name__ == '__main__':
# 方法一
for i in range(1,90,2):
print(i)
#方法二
num = 1 ;
while(num < 91):
if(num % 2 != 0):
print(num)
num+=1
#方法三
for i in range(90):
num = odd_number(i)
if num != None:
print(num)
先开启邮箱中的设置
点击账户
开启pop3/SMTP与IMAP/SMTP哦(很重要!!!)
import smtplib
from email.mime.text import MIMEText
email = 'smtp.qq.com'
from_addresses = '发送者@qq.com'
codes = 'xxxxxxxx'
to_addresses = '接收者@qq.com'
msg = MIMEText('连心爱的女人都留不住,python再吊有什么用!','plain','utf-8')
server = smtplib.SMTP_SSL(email)
server.connect(email,465)
server.login(from_addresses,codes )
server.sendmail(from_addresses,to_addresses,msg.as_string())
server.quit()
from turtle import *
# 设置色彩模式是RGB:
colormode(255)
lt(90)
lv = 14
l = 120
s = 45
width(lv)
# 初始化RGB颜色:
r = 0
g = 0
b = 0
pencolor(r, g, b)
penup()
bk(l)
pendown()
fd(l)
def draw_tree(l, level):
global r, g, b
# save the current pen width
w = width()
# narrow the pen width
width(w * 3.0 / 4.0)
# set color:
r = r + 1
g = g + 2
b = b + 3
pencolor(r % 200, g % 200, b % 200)
l = 3.0 / 4.0 * l
lt(s)
fd(l)
if level < lv:
draw_tree(l, level + 1)
bk(l)
rt(2 * s)
fd(l)
if level < lv:
draw_tree(l, level + 1)
bk(l)
lt(s)
# restore the previous pen width
width(w)
speed("fastest")
draw_tree(l, 4)
done()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
# 创建一个socket:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 建立连接:
s.connect(('www.sina.com.cn', 80))
# 发送数据:
s.send(b'GET / HTTP/1.1\r\nHost: www.sina.com.cn\r\nConnection: close\r\n\r\n')
# 接收数据:
buffer = []
while True:
# 每次最多接收1k字节:
d = s.recv(1024)
if d:
buffer.append(d)
else:
break
data = b''.join(buffer)
# 关闭连接:
s.close()
header, html = data.split(b'\r\n\r\n', 1)
print(header.decode('utf-8'))
# 把接收的数据写入文件:
with open('sina.html', 'wb') as f:
f.write(html)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
# 创建一个socket:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 建立连接:
s.connect(('www.sina.com.cn', 80))
# 发送数据:
s.send(b'GET / HTTP/1.1\r\nHost: www.sina.com.cn\r\nConnection: close\r\n\r\n')
# 接收数据:
buffer = []
while True:
# 每次最多接收1k字节:
d = s.recv(1024)
if d:
buffer.append(d)
else:
break
data = b''.join(buffer)
# 关闭连接:
s.close()
header, html = data.split(b'\r\n\r\n', 1)
print(header.decode('utf-8'))
# 把接收的数据写入文件:
with open('sina.html', 'wb') as f:
f.write(html)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 绑定端口:
s.bind(('127.0.0.1', 9999))
print('Bind UDP on 9999...')
while True:
# 接收数据:
data, addr = s.recvfrom(1024)
print('Received from %s:%s.' % addr)
reply = 'Hello, %s!' % data.decode('utf-8')
s.sendto(reply.encode('utf-8'), addr)
现象
爱美x之心人皆有之(爬虫获取妹纸图片,附加完整代码)_韶光不负的博客-CSDN博客
不在怕她说过我(python信息处理)_韶光不负的博客-CSDN博客
上车了,上车了(python爬取xx车数据)_韶光不负的博客-CSDN博客
爬取风景图片_韶光不负的博客-CSDN博客
有帮助不要忘了点赞哦!!!