Python学习

用turtle绘制直角三角形

import turtle as t

t.setup(600, 300, 200, 200)
t.penup()
t.fd(-40)
t.pendown()
t.pensize(15)
t.pencolor("blue")
t.fd(80)
t.seth(150)
t.fd(100)
t.seth(-90)
t.fd(60)
t.done()


爬取百度网站的HTML代码

from urllib import request

response = request.urlopen("https://baidu.com/")
content = response.read().decode('utf-8')
print(content)

快速排序

def quick_sort(num_list):
    q_sort(num_list, 0, len(num_list)-1)

def q_sort(num_list, first, last):
    if first < last:
        split = partition(num_list, first, last)
        q_sort(num_list, first, split-1)
        q_sort(num_list, split+1, last)

def partition(num_list, first, last):
    pivot = num_list[first]
    left_mark = first+1
    right_mark = last
    while True:
        while num_list[left_mark] <= pivot:
            if left_mark == right_mark:
                break
            left_mark +=1
        while num_list[right_mark] > pivot:
            right_mark -= 1
        if left_mark < right_mark:
            num_list[left_mark], num_list[right_mark] = num_list[right_mark], num_list[left_mark]
        else:
            break

    num_list[first], num_list[right_mark] = num_list[right_mark],num_list[first]
    return right_mark



def pop(num_list):
    for i in range(0, 8):
        for j in range(i, 8):
            if num_list[i]>num_list[j]:
               temp = num_list[j]
               num_list[j] = num_list[i]
               num_list[i] = temp


n_list = [5, -4, 6, 3, 7, 11, 1, 2]
print(f'排序之前:{str(n_list)}')
quick_sort(n_list)
print(f'排序之后:{str(n_list)}')
pop(n_list)
print(f'排序之后:{str(n_list)}')

Python控件

from tkinter import *

top = Tk()
text = 'hello world!'
bg = 'black'
fg = 'white'
font = ("黑体", 20, "bold")

bt_tk = Button(top, text=text, height=6, width=30, command=top.quit, bg=bg, fg=fg, font=font, activebackground='red', activeforeground='green')
bt_tk.pack()
top.mainloop()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值