
Python小例子
菩提树下祈愿的少年
QQ:951274168
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Python-OpenCV 寻找两条曲线直接的最短距离
import numpy as npimport mathimport cv2def cal_pt_distance(pt1, pt2): dist = math.sqrt(pow(pt1[0]-pt2[0],2) + pow(pt1[1]-pt2[1],2)) return distfont = cv2.FONT_HERSHEY_SIMPLEXimg = cv2.imread('01.png')#cv2.imshow('src',img)gray = cv2.cvtColor(i原创 2021-08-25 20:30:43 · 2222 阅读 · 0 评论 -
Python小例子——绘制水球图
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:绘制水球图"""from pyecharts import options as optsfrom pyecharts.charts import Liquid, Pagefrom pyecharts.globals import SymbolTypedef liquid() -> Liq...原创 2020-01-19 14:36:03 · 1308 阅读 · 0 评论 -
Python小例子——绘制时间线轮播图
代码如下:from pyecharts import options as optsfrom pyecharts.charts import Bar, Page, Pie, Timelinefrom random import randintdata = {'x': ['草莓', '芒果', '葡萄', '雪梨', '西瓜', '柠檬', '车厘子'], '沃尔玛': d...原创 2020-01-08 09:32:30 · 2255 阅读 · 1 评论 -
Python小例子——计算阶乘
"""作者:宇轩亚40功能:计算阶乘"""def factorial(n): if n == 1: result = 1 else: num = n * factorial(n-1) result = num return resulti = eval(input('请输入一个数:'))print('{}的阶乘为:{}'.forma...原创 2020-01-07 19:06:07 · 338 阅读 · 0 评论 -
Python小例子——定义累加数字
#自定义函数 -- 定义累加数字def total(num1, num2, num3): result = 0 #存储运算结果 for item in range(num1, num2+1, num3): result += item #数值相加 return result #返回运算结果print('计算数值总和:')key = input('按y...原创 2020-01-06 17:21:33 · 1273 阅读 · 1 评论 -
Python小例子——判断密码强弱
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:判断密码强弱"""def check_number_exist(password_str): """ 判断字符串中是否含有数字 """ has_number = False for c in password_str: if c.is...原创 2020-01-05 10:17:18 · 668 阅读 · 0 评论 -
Python小例子——使用科学计算库NumPy模拟掷骰子
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:使用科学计算库NumPy模拟掷骰子"""import matplotlib.pyplot as pltimport numpy as np#中文显示plt.rcParams['font.sans-serif'] = ['SimHei']plt.rcParams['axes.unico...原创 2020-01-04 21:14:15 · 731 阅读 · 0 评论 -
Python小例子——输入某年某月某日,判断这一天是这一年的第几天
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:输入某年某月某日,判断这一天是这一年的第几天?"""from datetime import datetimedef is_leap_year(year): """ 判断year是否为闰年,是返回True,否返回False """ is_leap = False...原创 2020-01-04 20:45:51 · 1204 阅读 · 0 评论 -
Python小例子——BMR计算器
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:BMR计算器"""def main(): """ 主函数 """ y_or_n = input('用户是否退出程序(y/n)?') while y_or_n == 'n': print('请输入以下信息,用空格分割') ...原创 2020-01-01 09:20:56 · 673 阅读 · 0 评论 -
Python小例子—— 52周存钱挑战
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:52周存钱挑战"""import mathimport datetimedef save_money_in_n_weeks(money_per_week, increase_money, total_week): """ 计算n周内的存款金额 """ saving...原创 2019-12-31 09:11:01 · 704 阅读 · 0 评论 -
Python小例子——利用递归绘制分形树
# -*- coding: utf-8 -*-""" 作者:宇轩亚40 功能:利用递归绘制分形树"""import turtledef draw_branch(branch_length): """ 绘制分型树 """ if branch_length > 5: #绘制右侧树枝 turtle.forward...原创 2019-12-30 08:40:23 · 744 阅读 · 0 评论 -
Python小例子——汇率计算
# -*- coding: utf-8 -*-"""作者:宇轩亚40功能:汇率计算新增功能:根据输入判断人民币还是美元,进行相应的转换计算"""# 输入金额currency_str_value = input('请输入带单位的货币金额:')# 取出单位unit = currency_str_value[-3:]#汇率USD_VS_RMB = 6.77if unit ==...原创 2019-12-29 09:45:20 · 623 阅读 · 0 评论