<jupyter_start><jupyter_text>循环- 循环是一种控制语句块重复执行的结构- while  适用于广度遍历- for    开发中经常使用<jupyter_code>while 1:
    print('你真是一个小机灵鬼')<jupyter_output><empty_output><jupyter_text>while 循环- 当一个条件保持真的时候while循环重复执行语句- while 循环一定要有结束条件，否则很容易进入死循环- while 循环的语法是：    while loop-contunuation-conndition:        Statement<jupyter_code>i = 0
while i<10:
    i +=1
    print('')
i = 0
a = 'abcd'
while i <4:
    
    print(a[i])
    i+=1<jupyter_output>a
b
c
d<jupyter_text>示例：sum = 0i = 1while i <10:    sum = sum + i    i = i + 1  错误示例：sum = 0i = 1while i <10:    sum = sum + ii = i + 1- 一旦进入死循环可按 Ctrl + c 停止  EP：![](../Photo/143.png)![](../Photo/144.png)<jupyter_code>number = eval(input('1:'))
max = number
while number != 0 :
    number = eval(input('2:'))
    if number > max:
        max = number
print('max is ',max)
print('number',number)<jupyter_output>1:2
2:3
2:4
2:5
2:0
max is  5
number 0<jupyter_text>验证码- 随机产生四个字母的验证码，如果正确，输出验证码正确。如果错误，产生新的验证码，用户重新输入。- 验证码只能输入三次，如果三次都错，返回“别爬了，我们小网站没什么好爬的”- 密码登录，如果三次错误，账号被锁定<jupyter_code>import random
j=0
while j<3:
    a = ''
    for i in range(4):
        b = chr(random.randint(65,90))
        a += b
    print(a)
    c =str(input('请输入验证码：'))
    if c == a:
        print('太棒了')
        break
    else :
        print('你错啦')
        j +=1
    if j ==3:
        print('别爬了，我们小网站没什么好爬的')
j=0
password = '<PASSWORD>'
i = 0
if j !=3:
    while i < 3:
        pass_=input('>>')
        if pass_ == password:
            print('OK')
            break
        else:
            print('Error')
            i +=1
    j = i
else:
    print('账号锁定')
yanzhengma = ''
j =0
while j < 3:
    for i in range(4):
        random_1 = chr(random.randint(65,90))
        yanzhengma += random_1
    print(yanzhengma)
    input_ = input('>>')
    if input_ == yanzhengma:
        print('OK')
        break
    else:
        print('Error')
        yanzhengma = ''
        j +=1
    if j ==3:
        print('别爬了')
import matplotlib.pyplot as plt
x_list=[]
y_list=[]
c_list=[-50,50,1]
for x in range(-50,50,1):
    y = x**2
    x_list.append(x)
    y_list.append(y)
print(x_list,y_list)
plt.plot(x_list,y_list,c_list)
plt.show()
# coding:utf-8
__author__ = 'taohao'
import matplotlib.pyplot as plt
from matplotlib import animation
import numpy as np
import math
 
 
def drawHeart():
    t = np.linspace(0, math.pi, 1000)
    x = np.sin(t)
    y = np.cos(t) + np.power(x, 2.0/3)
    plt.plot(x, y, color='red', linewidth=2, label='h')
    plt.plot(-x, y, color='red', linewidth=2, label='-h')
    plt.xlabel('t')
    plt.ylabel('h')
    plt.ylim(-2, 2)
    plt.xlim(-2, 2)
    
    plt.legend()
    plt.show()
 
drawHeart()<jupyter_output><empty_output><jupyter_text>尝试死循环  实例研究：猜数字- 你将要编写一个能够随机生成一个0到10之间的且包括两者的数字程序，这个程序- 提示用户连续地输入数字直到正确，且提示用户输入的数字是过高还是过低<jupyter_code>import random
a = random.randint(0,10)
print(a)
b = eval(input('请输入这个数字：'))

while a != b:
    b = eval(input('请重新输入这个数字：'))
if a ==b:
    print('ok')<jupyter_output>3
请输入这个数字：4
请重新输入这个数字：8
请重新输入这个数字：6
请重新输入这个数字：3
ok<jupyter_text>使用哨兵值来控制循环- 哨兵值来表明输入的结束- ![](../Photo/54.png)  警告![](../Photo/55.png)  for 循环- Python的for 循环通过一个序列中的每个值来进行迭代- range(a,b,k)， a，b，k 必须为整数- a: start- b: end- k: step- 注意for 是循环一切可迭代对象，而不是只能使用range  在Python里面一切皆对象  EP:- ![](../Photo/145.png)<jupyter_code>i =0
number =0
sum=0
for count in range(5):
    number = eval(input(''))
    sum += number
print(sum)
print(count)
i = 0
sum = 0
while i<1001:
    sum = sum+i
    i+=1
print(sum)<jupyter_output>500500<jupyter_text>嵌套循环- 一个循环可以嵌套另一个循环- 每次循环外层时，内层循环都会被刷新重新完成循环- 也就是说，大循环执行一次，小循环会全部执行一次- 注意：> - 多层循环非常耗时  - 最多使用3层循环<jupyter_code>for i in ra<jupyter_output><empty_output><jupyter_text>EP：- 使用多层循环完成9X9乘法表- 显示50以内所有的素数<jupyter_code>for i in range(1,10):
    for j in range(1,i+1):
        print(i,'*',j,'=',(i*j),end=' ')
    print()
for i in range(2,50):
    for j in range(2,i):
        if i % j ==0:
            break
    else:
         print(i,end=' ')<jupyter_output>2 3 5 7 11 13 17 19 23 29 31 37 41 43 47<jupyter_text>关键字 break 和 continue- break 跳出循环，终止循环- continue 跳出此次循环，继续执行  注意![](../Photo/56.png)![](../Photo/57.png)  Homework- 1 ![](../Photo/58.png)<jupyter_code>i =0
b = 0
a = eval(input('请输入一个数：'))
while a !=0:
    b = a+b
    i = i+1
    a = eval(input('请再输入一个数：'))
print(b/i)<jupyter_output>请输入一个数：1
请再输入一个数：2
请再输入一个数：0
1.5<jupyter_text>- 2![](../Photo/59.png)<jupyter_code>sum = 10000
i = 0
while i < 11:
    sum = sum + sum * 0.05
    i = i+1
print(round(sum,2))
j = sum
k = j + j*0.05
l = k + k*0.05
b = l + l*0.05
n = k+l+b+j
print('十年后大学四年的学费是',round(n,2))<jupyter_output>17103.39
十年后大学四年的学费是 73717.76<jupyter_text>- 3![](../Photo/58.png) - 4![](../Photo/60.png)<jupyter_code>for i in range(100,1000):
    if i % 5==0 and i % 6 ==0:
        print(i,end=' ')<jupyter_output>120 150 180 210 240 270 300 330 360 390 420 450 480 510 540 570 600 630 660 690 720 750 780 810 840 870 900 930 960 990<jupyter_text>- 5![](../Photo/61.png)<jupyter_code>n = 1
b = 1
while n*n <12000:
    n = n +1
print(n)
while b*b*b <12000:
    b = b +1
print(b)<jupyter_output>110
23<jupyter_text>- 6![](../Photo/62.png) - 7![](../Photo/63.png)<jupyter_code>a=0
for n in range(1,50001):
    a = a+1/n
print(a)

n=50000
s=0
while n>0:
    s = s+1/n
    n =n-1
print(s)<jupyter_output>11.397003949278504
11.397003949278519<jupyter_text>- 8![](../Photo/64.png)<jupyter_code>i=1
sum=0
while i<98:
    sum+=i /(i+2)
    i = i+2
print(sum)<jupyter_output>45.124450303050196<jupyter_text>- 9![](../Photo/65.png) - 10 ![](../Photo/66.png) - 11![](../Photo/67.png)<jupyter_code>a = 0
for i in range(1,7):
    for j in range(1,7):
        a=a+1
        print(i,j)
print(a)<jupyter_output>1 1
1 2
1 3
1 4
1 5
1 6
2 1
2 2
2 3
2 4
2 5
2 6
3 1
3 2
3 3
3 4
3 5
3 6
4 1
4 2
4 3
4 4
4 5
4 6
5 1
5 2
5 3
5 4
5 5
5 6
6 1
6 2
6 3
6 4
6 5
6 6
36<jupyter_text>- 12![](../Photo/68.png)<jupyter_code>1 **2 + 2**2 + 3**2 + 5.5 *2 + 5.6 **2 + 6 **2 + 7**2 + 8**2 + 9 **2 + 10 **2
1  + 2 + 3 + 5.5  + 5.6 + 6 + 7 + 8+ 9  + 10<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17572312322354122, 'fraction_numerical': 0.09446580839324528, 'mean_word_length': 3.0282828282828285, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '129162', 'license': 'Apache-2.0', 'n_tokens_mistral': 3461, 'n_tokens_neox': 3253, 'n_words': 621, 'path': '7.19.ipynb', 'repo_name': 'starjiejie/STAR', 'size': '5976'}