上一页 1 ··· 10 11 12 13 14
摘要: 一段简单的猜数字代码,要求是1,要猜的数字是随机数字1到9;2,猜数字次数为三次;3,如果猜中就打印提示语,并且结束程序;4,如果猜错就打印正确值还有剩下的次数;5,如果次数为0,就打印结束,欢迎下次再来。 文件名为:easy_guess.py,代码如下: 1 # !usr/bin/env pyth 阅读全文
posted @ 2020-06-15 10:14 、一叶孤城 阅读(1352) 评论(0) 推荐(0)
摘要: 在撸码过程中,总有很多代码需要重构,码一个问候用户的小例子,加深对代码重构的印象。 原始代码: 1 import json 2 3 filename = 'username.json' #定义文件名 4 5 try: 6 with open(filename) as file_object: 7 u 阅读全文
posted @ 2020-06-02 13:01 、一叶孤城 阅读(2260) 评论(0) 推荐(2)
摘要: python之使用pygal模拟掷两颗面数为6的骰子的直方图,包含三个文件,主文件,die.py,dice_visual.py,20200527.svg。其中最后一个文件为程序运行得到的结果。 1,die.py,原码如下: 1 from random import randint 2 3 class 阅读全文
posted @ 2020-05-27 12:02 、一叶孤城 阅读(362) 评论(0) 推荐(0)
摘要: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 <title>一个简单的CSS示例</title> 6 <style> 7 .main{ 8 width: 800px; 9 margin: 0 auto; 10 } 1 阅读全文
posted @ 2020-05-22 15:49 、一叶孤城 阅读(249) 评论(0) 推荐(0)
摘要: 最近有点懒,没码什么字,防止遗忘,从头开始码,写一个简单的HTML留言板。包含两个文件,book.html还有style.css,放在同一目录下。 book.html 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8" /> 5 < 阅读全文
posted @ 2020-05-22 15:33 、一叶孤城 阅读(11257) 评论(2) 推荐(1)
摘要: python之使用pygal模拟掷骰子创建直方图: 1,文件die.py,源码如下: 1 from random import randint 2 3 class Die(): 4 '''表示一个骰子的类''' 5 def __init__(self,num_sides = 6): 6 '''初始化 阅读全文
posted @ 2020-05-20 16:36 、一叶孤城 阅读(196) 评论(0) 推荐(0)
摘要: Matplotlib之scatter 1,使用scatter绘制散点图并设置其样式: 1 import matplotlib.pyplot as plt 2 3 '''使用scatter绘制散点图并设置其样式''' 4 square = [1,4,s=200] 5 6 plt.title("Squa 阅读全文
posted @ 2020-05-19 10:00 、一叶孤城 阅读(724) 评论(0) 推荐(0)
摘要: 1,绘制简单的折线图。 1 import matplotlib.pyplot as plt 2 3 square = [1,4,9,16,25] 4 5 plt.plot(square) 6 plt.show() 2,使用matplotlib修改折现图的标签文字和线条粗细。 1 '''修改标签文字和 阅读全文
posted @ 2020-05-19 09:29 、一叶孤城 阅读(236) 评论(0) 推荐(0)
上一页 1 ··· 10 11 12 13 14