<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>生错了家庭的苦孩子</title>
        <link>https://paragraph.com/@0xaed7ea561819b8734aa828fdfffe1657035fcaf7</link>
        <description>家庭和学校毁了我</description>
        <lastBuildDate>Mon, 10 Aug 2026 06:08:57 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>生错了家庭的苦孩子</title>
            <url>https://storage.googleapis.com/papyrus_images/17f335b4cebab9b6ac35ab9a6222f2d4adefb2a9c4e3d382a0a9fdbc0ec57f26.png</url>
            <link>https://paragraph.com/@0xaed7ea561819b8734aa828fdfffe1657035fcaf7</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[美女5]]></title>
            <link>https://paragraph.com/@0xaed7ea561819b8734aa828fdfffe1657035fcaf7/5</link>
            <guid>EkIyM0fIvXaMXZ17vhpN</guid>
            <pubDate>Sun, 15 May 2022 11:09:50 GMT</pubDate>
            <content:encoded><![CDATA[<figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/0d6de0494c259ccc4dd60b5152629e21adfce1c6db450e8943abec91759944a0.jpg" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure>]]></content:encoded>
            <author>0xaed7ea561819b8734aa828fdfffe1657035fcaf7@newsletter.paragraph.com (生错了家庭的苦孩子)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/66f16d5323ce8d999e9a2401dcfc96a19ff639859b8c5654fc573cb3aa245007.jpg" length="0" type="image/jpg"/>
        </item>
        <item>
            <title><![CDATA[PYTHON学习100天之第四天]]></title>
            <link>https://paragraph.com/@0xaed7ea561819b8734aa828fdfffe1657035fcaf7/python-100</link>
            <guid>0XpjfhHlEByb5Tg6fvab</guid>
            <pubDate>Sun, 08 May 2022 15:38:03 GMT</pubDate>
            <description><![CDATA[https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/04.%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84.md 循环结构 应用场景 我们在写程序的时候，一定会遇到需要重复执行某条或某些指令的场景。例如用程序控制机器人踢足球，如果机器人持球而且还没有进入射门范围，那么我们就要一直发出让机器人向球门方向移动的指令。在这个场景中，让机器人向球门方向移动就是一个需要重复的动作，当然这里还会用到上一课讲的分支结构来判断机器人是否持球以及是否进入射门范围。再举一个简单的例子，如果要实现每隔1秒中在屏幕上打印一次“hello, world”并持续打印一个小时，我们肯定不能够直接把print(&apos;hello, world&apos;)这句代码写3600遍，这里同样需要循环结构。 循环结构就是程序中控制某条或某些指令重复执行的结构。在Python中构造循环结构有两种做法，一种是for-in循环，一种是while循环。 for-in循环 如果明确的知道循环执行的次数或者要对一个容器进行迭...]]></description>
            <content:encoded><![CDATA[<p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/04.%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84.md">https://github.com/jackfrued/Python-100-Days/blob/master/Day01-15/04.%E5%BE%AA%E7%8E%AF%E7%BB%93%E6%9E%84.md</a></p><p>循环结构 应用场景 我们在写程序的时候，一定会遇到需要重复执行某条或某些指令的场景。例如用程序控制机器人踢足球，如果机器人持球而且还没有进入射门范围，那么我们就要一直发出让机器人向球门方向移动的指令。在这个场景中，让机器人向球门方向移动就是一个需要重复的动作，当然这里还会用到上一课讲的分支结构来判断机器人是否持球以及是否进入射门范围。再举一个简单的例子，如果要实现每隔1秒中在屏幕上打印一次“hello, world”并持续打印一个小时，我们肯定不能够直接把print(&apos;hello, world&apos;)这句代码写3600遍，这里同样需要循环结构。</p><p>循环结构就是程序中控制某条或某些指令重复执行的结构。在Python中构造循环结构有两种做法，一种是for-in循环，一种是while循环。</p><p>for-in循环 如果明确的知道循环执行的次数或者要对一个容器进行迭代（后面会讲到），那么我们推荐使用for-in循环，例如下面代码中计算1~100求和的结果（$\displaystyle \sum \limits_{n=1}^{100}n$）。</p><p>&quot;&quot;&quot; 用for循环实现1~100求和</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot;</p><p>sum = 0 for x in range(101): sum += x print(sum) 需要说明的是上面代码中的range(1, 101)可以用来构造一个从1到100的范围，当我们把这样一个范围放到for-in循环中，就可以通过前面的循环变量x依次取出从1到100的整数。当然，range的用法非常灵活，下面给出了一个例子：</p><p>range(101)：可以用来产生0到100范围的整数，需要注意的是取不到101。 range(1, 101)：可以用来产生1到100范围的整数，相当于前面是闭区间后面是开区间。 range(1, 101, 2)：可以用来产生1到100的奇数，其中2是步长，即每次数值递增的值。 range(100, 0, -2)：可以用来产生100到1的偶数，其中-2是步长，即每次数字递减的值。 知道了这一点，我们可以用下面的代码来实现1~100之间的偶数求和。</p><p>&quot;&quot;&quot; 用for循环实现1~100之间的偶数求和</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot;</p><p>sum = 0 for x in range(2, 101, 2): sum += x print(sum) 当然，也可以通过在循环中使用分支结构的方式来实现相同的功能，代码如下所示。</p><p>&quot;&quot;&quot; 用for循环实现1~100之间的偶数求和</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot;</p><p>sum = 0 for x in range(1, 101): if x % 2 == 0: sum += x print(sum) 说明：相较于上面直接跳过奇数的做法，下面这种做法很明显并不是很好的选择。</p><p>while循环 如果要构造不知道具体循环次数的循环结构，我们推荐使用while循环。while循环通过一个能够产生或转换出bool值的表达式来控制循环，表达式的值为True则继续循环；表达式的值为False则结束循环。</p><p>下面我们通过一个“猜数字”的小游戏来看看如何使用while循环。猜数字游戏的规则是：计算机出一个1到100之间的随机数，玩家输入自己猜的数字，计算机给出对应的提示信息（大一点、小一点或猜对了），如果玩家猜中了数字，计算机提示用户一共猜了多少次，游戏结束，否则游戏继续。</p><p>&quot;&quot;&quot; 猜数字游戏</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot; import random</p><p>answer = random.randint(1, 100) counter = 0 while True: counter += 1 number = int(input(&apos;请输入: &apos;)) if number &lt; answer: print(&apos;大一点&apos;) elif number &gt; answer: print(&apos;小一点&apos;) else: print(&apos;恭喜你猜对了!&apos;) break print(&apos;你总共猜了%d次&apos; % counter) if counter &gt; 7: print(&apos;你的智商余额明显不足&apos;) 上面的代码中使用了break关键字来提前终止循环，需要注意的是break只能终止它所在的那个循环，这一点在使用嵌套的循环结构（下面会讲到）需要引起注意。除了break之外，还有另一个关键字是continue，它可以用来放弃本次循环后续的代码直接让循环进入下一轮。</p><p>和分支结构一样，循环结构也是可以嵌套的，也就是说在循环中还可以构造循环结构。下面的例子演示了如何通过嵌套的循环来输出一个九九乘法表。</p><p>&quot;&quot;&quot; 输出乘法口诀表(九九表)</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot;</p><p>for i in range(1, 10): for j in range(1, i + 1): print(&apos;%d*%d=%d&apos; % (i, j, i * j), end=&apos;\t&apos;) print() 练习 练习1：输入一个正整数判断是不是素数。 提示：素数指的是只能被1和自身整除的大于1的整数。</p><p>参考答案：</p><p>&quot;&quot;&quot; 输入一个正整数判断它是不是素数</p><p>Version: 0.1 Author: 骆昊 Date: 2018-03-01 &quot;&quot;&quot; from math import sqrt</p><p>num = int(input(&apos;请输入一个正整数: &apos;)) end = int(sqrt(num)) is_prime = True for x in range(2, end + 1): if num % x == 0: is_prime = False break if is_prime and num != 1: print(&apos;%d是素数&apos; % num) else: print(&apos;%d不是素数&apos; % num) 练习2：输入两个正整数，计算它们的最大公约数和最小公倍数。 提示：两个数的最大公约数是两个数的公共因子中最大的那个数；两个数的最小公倍数则是能够同时被两个数整除的最小的那个数。</p><p>参考答案：</p><p>&quot;&quot;&quot; 输入两个正整数计算它们的最大公约数和最小公倍数</p><p>Version: 0.1 Author: 骆昊 Date: 2018-03-01 &quot;&quot;&quot;</p><p>x = int(input(&apos;x = &apos;)) y = int(input(&apos;y = &apos;))</p><h1 id="h-xyxy" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">如果x大于y就交换x和y的值</h1><p>if x &gt; y: # 通过下面的操作将y的值赋给x, 将x的值赋给y x, y = y, x</p><h1 id="h-" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">从两个数中较小的数开始做递减的循环</h1><p>for factor in range(x, 0, -1): if x % factor == 0 and y % factor == 0: print(&apos;%d和%d的最大公约数是%d&apos; % (x, y, factor)) print(&apos;%d和%d的最小公倍数是%d&apos; % (x, y, x * y // factor)) break 练习3：打印如下所示的三角形图案。 * **</p><hr><hr><hr><pre data-type="codeBlock" text="*
"><code><span class="hljs-bullet">*</span>
</code></pre><p>**</p><hr><hr><hr><pre data-type="codeBlock" text="*
"><code><span class="hljs-bullet">*</span>
</code></pre><hr><hr><hr><hr><p>参考答案：</p><p>&quot;&quot;&quot; 打印三角形图案</p><p>Version: 0.1 Author: 骆昊 &quot;&quot;&quot;</p><p>row = int(input(&apos;请输入行数: &apos;)) for i in range(row): for _ in range(i + 1): print(&apos;*&apos;, end=&apos;&apos;) print()</p><p>for i in range(row): for j in range(row): if j &lt; row - i - 1: print(&apos; &apos;, end=&apos;&apos;) else: print(&apos;*&apos;, end=&apos;&apos;) print()</p><p>for i in range(row): for _ in range(row - i - 1): print(&apos; &apos;, end=&apos;&apos;) for _ in range(2 * i + 1): print(&apos;*&apos;, end=&apos;&apos;) print() © 2022 GitHub, Inc. Terms Privacy</p>]]></content:encoded>
            <author>0xaed7ea561819b8734aa828fdfffe1657035fcaf7@newsletter.paragraph.com (生错了家庭的苦孩子)</author>
        </item>
    </channel>
</rss>