<jupyter_start><jupyter_text>循环- 循环是一种控制语句块重复执行的结构- while  适用于广度遍历- for    开发中经常使用  while 循环- 当一个条件保持真的时候while循环重复执行语句- while 循环一定要有结束条件，否则很容易进入死循环- while 循环的语法是：    while loop-contunuation-conndition:        Statement  示例：sum = 0i = 1while i <10:    sum = sum + i    i = i + 1  错误示例：sum = 0i = 1while i <10:    sum = sum + ii = i + 1- 一旦进入死循环可按 Ctrl + c 停止<jupyter_code>import os
i = 0
while 1:
    os.system('calc')
i=0
while i < 10:
    print('今天天气好晴朗')
    i +=1<jupyter_output>今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗
今天天气好晴朗<jupyter_text>EP：![](../Photo/143.png)![](../Photo/144.png)  验证码- 随机产生四个字母的验证码，如果正确，输出验证码正确。如果错误，产生新的验证码，用户重新输入。- 验证码只能输入三次，如果三次都错，返回“别爬了，我们小网站没什么好爬的”- 密码登录，如果三次错误，账号被锁定<jupyter_code>import random
yanzhemgma=random.randint(1000,9999)
print('验证码为',yanzhengma)
me=eval(input('输入四个数字的验证码'))

if me == yanzhengma:
    print('验证码输入正确')
    break
    print(',,,')#如果break了，则break之后的代码都不运行
else:
    print('验证码输入错误')
while True:
    n1=chr(random.randint(97,122))
    n2=chr(random.randint(97,122))
    n3=chr(random.randint(97,122))
    n4=chr(random.randint(97,122))
    N=n1 + n2 + n3 + n4
    print('验证码是',N)
    me=input('输入验证码')
    
    if me==N:
        print('验证码正确')
        break
    else:
        print('验证码错误')
while True:
    n1=chr(random.randint(65,90))
    n2=chr(random.randint(97,122))
    n3=chr(random.randint(97,122))
    n4=chr(random.randint(97,122))
    shuffle_n=[n1,n2,n3,n4]
    random.shuffle(shuffle_n)
    N="".join(shuffle_n)
    print('验证码是',N)
    me=input('输入验证码')
    
    if me==N:
        print('验证码正确')
        break
    else:
        print('验证码错误')
import random
while True:
    n1=chr(random.randint(65,90))
    n2=chr(random.randint(97,122))
    n3=chr(random.randint(97,122))
    n4=chr(random.randint(97,122))
    shuffle_n=[n1,n2,n3,n4]
    random.shuffle(shuffle_n) 
    N="".join(shuffle_n)
    print('验证码是',N)
    me=input('输入验证码')
    
    if me.lower()==N.lower():
        print('验证码正确')
        break
    else:
        print('验证码错误')
import random
while True:
    choose = random(0,1)
    list_=[[65,90],[97,122]]
    print('验证码是',N)
    me=input('输入验证码')
    
    if me.lower()==N.lower():
        print('验证码正确')
        break
    else:
        print('验证码错误')
import random
a=[1,2,3,4,5]
random.shuffle(a)  #随机打乱
a
import random
while True:
    choose = random.randint(0,1)
    list_=[[65,90],[97,122]]
    range_=list_[choose]
    N=""
    for i in range(4):
        N+=chr(random.randint(range_[0],range_[1]))
    print('验证码是',N)
    me=input('输入验证码')
    if me.lower()==N.lower():
        print('验证码正确')
        break
    else:
        print('验证码正确')<jupyter_output>验证码是 drkl
输入验证码drkL
验证码正确<jupyter_text>尝试死循环  实例研究：猜数字- 你将要编写一个能够随机生成一个0到10之间的且包括两者的数字程序，这个程序- 提示用户连续地输入数字直到正确，且提示用户输入的数字是过高还是过低<jupyter_code>import random
while 1:
    N1 = random.randint(0,10)
    N2 = random.randint(0,10)
    input_ = eval(input('Sum'))
    if N1 + N2==input_:
        print('Correct!!')
        break<jupyter_output><empty_output><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<jupyter_code>#次数
for i in range(10,0,-1):
    print(i)
for i in range(0,10,2):
    print(i)
range(10).__iter__()#可迭代   才能用for循环
a = []
a.__iter__<jupyter_output><empty_output><jupyter_text>在Python里面一切皆对象  EP:- ![](../Photo/145.png)<jupyter_code>i = 1
sum_ = 0
while sum_<10000:
    sum_ = sum_ + i
    i+= 1
print(i)
print(sum_)

sum_ = 0
for i in range(1,10000):
    sum_= sum_ + i
    if sum_>10000:
        break
print(sum_)
print(i)
sum_= 0
for i in range(1001):
    sum_ = sum_ + 1
print(sum_)
sum_ = 0
while sum_ < 1001:
    sum_+= 1
print(sum_)<jupyter_output>1001<jupyter_text>嵌套循环- 一个循环可以嵌套另一个循环- 每次循环外层时，内层循环都会被刷新重新完成循环- 也就是说，大循环执行一次，小循环会全部执行一次- 注意：> - 多层循环非常耗时  - 最多使用3层循环  EP：- 使用多层循环完成9X9乘法表- 显示50以内所有的素数<jupyter_code>for i in range(1,10):
    for j in range(1,i+1):
        print('%d*%d=%d'%(j,i,i*j),end=" ")
    print()
list = []
for i in range(2,50):
    if i < 2:
        continue
    for j in range(2,i):
        if i % j == 0:
            break
        else:
            list.append(i) 
print(list)<jupyter_output>[3, 5, 5, 5, 7, 7, 7, 7, 7, 9, 11, 11, 11, 11, 11, 11, 11, 11, 11, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 15, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 21, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 25, 25, 25, 27, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 33, 35, 35, 35, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 39, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 4[...]<jupyter_text>关键字 break 和 continue- break 跳出循环，终止循环- continue 跳出此次循环，继续执行<jupyter_code>for i in range(10):
    if i == 5:
        continue
print(i)
for i in range(10):
    for j in range(10):
        for k in range(10):
            print(i,j,k)
for i in range(10):
    if i == 5:
        break
print(i)
for i in range(10):
    if i == 5:
        continue
print(i)
for i in range(10):
    for j in range(10):
        print(i,j)
        if j ==5:
            break<jupyter_output>0 0
0 1
0 2
0 3
0 4
0 5
1 0
1 1
1 2
1 3
1 4
1 5
2 0
2 1
2 2
2 3
2 4
2 5
3 0
3 1
3 2
3 3
3 4
3 5
4 0
4 1
4 2
4 3
4 4
4 5
5 0
5 1
5 2
5 3
5 4
5 5
6 0
6 1
6 2
6 3
6 4
6 5
7 0
7 1
7 2
7 3
7 4
7 5
8 0
8 1
8 2
8 3
8 4
8 5
9 0
9 1
9 2
9 3
9 4
9 5<jupyter_text>注意![](../Photo/56.png)![](../Photo/57.png) - 2![](../Photo/59.png)<jupyter_code>money = 10000
i=1
if i <10:
    money += money*(5/100)
    i += 1
print(money)<jupyter_output>10500.0<jupyter_text>- 3![](../Photo/58.png) - 4![](../Photo/60.png)<jupyter_code>count = 0
for i in range(100,1000):
    if i % 5!=0 and i % 6 !=0:
        continue
    elif i % 5==0 and i % 6 ==0:
        print(i)
        count+=1
        if count % 10 == 0:
            print("")
            count=0
        else:
            continue<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
while n*n <12000:
    n=n+1
    continue
print(n)
n=1
while n*n*n<12000:
    n=n+1
    continue
print((n))<jupyter_output>23<jupyter_text>- 6![](../Photo/62.png)<jupyter_code>dai=eval(input('输入贷款数'))
zhouqi=eval(input('输入以年为单位的贷款周期'))<jupyter_output><empty_output><jupyter_text>- 7![](../Photo/63.png)<jupyter_code>i = 1
a = i
while i<50000:
    i += 1
    a += 1/i
print(a)<jupyter_output>11.397003949278504<jupyter_text>- 8![](../Photo/64.png)<jupyter_code>sum = 0
for i in range(3,100,2):
    sum += (i-2)/i
print(sum)<jupyter_output>45.124450303050196<jupyter_text>- 9![](../Photo/65.png)<jupyter_code>i=10000
for i in range(10):
    pi=4(1-1/3+1/5-1/7+1/9-1/11+...+(-1^(i+1))/2*i-1)
    i +=10000
print(pi)<jupyter_output><empty_output><jupyter_text>- 10 ![](../Photo/66.png)<jupyter_code>for i in range(1,10000):
    s = 0
    for k in range(1,i):
        if i % k == 0:
            s = s+k
    if i ==s:
        print(i)<jupyter_output>6
28
496
8128<jupyter_text>- 11![](../Photo/67.png)<jupyter_code>tmp=[]
for i in range(1,8):
    for j in range(1,8):
        if i != j and sorted([i,j]) not in tmp:#sorted返回数值 
            tmp.append([i,j])#追加
    print(tmp)
    print(len(tmp))#个数的统计<jupyter_output>[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7]]
6
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7]]
11
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7]]
15
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7]]
18
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7]]
20
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]]
21
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]]
21<jupyter_text>- 12![](../Photo/68.png)<jupyter_code>i=0
for i in range(10):
    mean = (x1+x2+...+xn)/n
    deviation=<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20970074535543443, 'fraction_numerical': 0.15452219379241294, 'mean_word_length': 2.9813994685562446, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 137, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '190868', 'license': 'Apache-2.0', 'n_tokens_mistral': 5737, 'n_tokens_neox': 4939, 'n_words': 1141, 'path': '7.19.ipynb', 'repo_name': 'SSS980818/mysql', 'size': '8989'}