<jupyter_start><jupyter_text>选择 布尔类型、数值和表达式(true、false)![](../Photo/33.png)- 注意：比较运算符的相等是两个等号，一个等到代表赋值- 在Python中可以用整型0来代表False，其他数字来代表True- 后面还会讲到 is 在判断语句中的用发<jupyter_code>a=1
b=1
a==b
a=1
b='1'
a==b
a=1
b=1.0
a==b
a='1'
b='2'
a>b
a=1
b='2'
a>b
0 is 1<jupyter_output><empty_output><jupyter_text>字符串的比较使用ASCII值（大写字母排在小写字母前）小写排在前面的小<jupyter_code>a='cy'
b='hsh'
a>b<jupyter_output><empty_output><jupyter_text>Markdown - https://github.com/younghz/Markdown $x = 2x+1$  EP:- - 输入一个数字，判断其实奇数还是偶数<jupyter_code>int(True)
int(False)
bool(4)
bool(0)
i=eval(input('shuruzhi'))
if i%2 == 0:
    print("shi ou shu")
else:
    print('shi ji shu ')
i=eval(input('shuruzhi'))
if not bool(i%2):
    print("shi ou shu")
else:
    print('shi ji shu ')<jupyter_output>shuruzhi5
shi ji shu<jupyter_text>产生随机数字- 函数random.randint(a,b) 可以用来产生一个a和b之间且包括a和b的随机整数 产生一个随机数，你去输入，如果你输入的数大于随机数，那么就告诉你太大了，反之，太小了，然后你一直输入，知道它满意为止<jupyter_code>import random
random.randint(2,3)
i=eval(input('输入数'))
c=random.randint(1,10)
if i>10:
    print('太大了')
if i<1:
    print('太小了')
if 1<i<10:
    print(c)
   

c=random.randint(1,10）
import random
while 1:
    i=eval(input('输入数'))
    if i>c:
        print('太大了')
    if i<c:
        print('太小了')
    if i==c:
        print('正确')
        break<jupyter_output>输入数5
太大了
输入数6
太大了
输入数1
正确<jupyter_text>其他random方法- random.random 返回0.0到1.0之间前闭后开区间的随机浮点- random.randrange(a,b) 前闭后开范围<jupyter_code>random.randrange(5,10)
random.random()<jupyter_output><empty_output><jupyter_text>EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字的和，并判定其是否正确- 进阶:写一个随机序号点名程序<jupyter_code>import random
a=random.randrange(5,10)
b=random.randrange(5,9)
c=a+b
number=0
while number<5:
    d=eval(input('请输入和'))
    if d!=c:
        print('caicuo')
    if d== c:
        print('c')
        break
    number +=1
    


x=eval(input('输入一个数'))

for i in range(2,x):
    if x%i==0:
        print(i,'可以整除')
#输入一个数字可以整除2、3<jupyter_output><empty_output><jupyter_text>if语句- 如果条件正确就执行一个单向if语句，亦即当条件为真的时候才执行if内部的语句- Python有很多选择语句:> - 单向if   - 双向if-else  - 嵌套if  - 多向if-elif-else  - 注意：当语句含有子语句的时候，那么一定至少要有一个缩进，也就是说如果有儿子存在，那么一定要缩进- 切记不可tab键和space混用，单用tab 或者 space- 当你输出的结果是无论if是否为真时都需要显示时，语句应该与if对齐  EP：- 用户输入一个数字，判断其实奇数还是偶数- 进阶：可以查看下4.5实例研究猜生日  双向if-else 语句- 如果条件为真，那么走if内部语句，否则走else内部语句  EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字，并判定其是否正确,如果正确打印“you‘re correct”，否则打印正确错误  嵌套if 和多向if-elif-else![](../Photo/35.png)<jupyter_code>x=input('有钱吗')
x1='有钱'
b1='帅'
c1='有老婆'
if x1==x:
    print('yes')
    b=input('帅不帅呀')
    if b1==b:
        print('有没有老婆哦')
        a=input("")
        if a==c1:
            print("滚")
        else:
            print('见一面')
    else:
        print('考虑')
else:
    print('gun')
    
money= input('money[y/n]')
if money =='y':
    print('再问一个问题~')
    h=input('handsome[y/n]')
    if h=='y':
        print('再问一个问题')
        c=input('wife[y/n]')
        if c=='y':
            print('考虑')
        else:
            print('马上结婚')
    else:
        print('考虑一下')
else:
    print('gun~')
a=input('a[y/n]')
if a=='y':
    print('再问一个问题')
    b=input('b[y/n]')
    if b=='y':
        c=input('c[y/n]')
        if c=='y':
            print('有老婆，考虑一下')
        elif c=='n':
            print('马上结婚')
    elif b=='n':
        print('考虑一下')
elif a=='n':
    print('gun')<jupyter_output>a[y/n]y
再问一个问题
b[y/n]y
c[y/n]y
有老婆，考虑一下<jupyter_text>EP：- 提示用户输入一个年份，然后显示表示这一年的动物![](../Photo/36.png)- 计算身体质量指数的程序- BMI = 以千克为单位的体重除以以米为单位的身高的平方![](../Photo/37.png)<jupyter_code>x=eval(input('输入年份'))
if x%12==0:
    print('猴')
elif x%12==1:
    print('鸡')
elif x%12==2:
    print('狗')
elif x%12==3:
    print('猪')
elif x%12==4:
    print('鼠')
elif x%12==5:
    print('牛')
elif x%12==6:
    print('虎')
elif x%12==7:
    print('兔')
elif x%12==8:
    print('龙')
elif x%12==9:
    print('蛇')
elif x%12==10:
    print('马')
elif x%12==11:
    print('羊')
    











wigh=eval(input('输入体重'))
high=eval(input('输入身高'))
bmi=wigh/high/high
if bmi<18.5:
    print('超轻')
elif 18.5<=bmi<25.0:
    print('标准')
elif 25.0<=bmi<30.0:
    print('超重')
elif bmi>=30.0:
    print('痴肥')<jupyter_output>输入体重60
输入身高1.55
标准<jupyter_text>逻辑运算符![](../Photo/38.png) ![](../Photo/39.png)![](../Photo/40.png)  EP：- 判定闰年：一个年份如果能被4整除但不能被100整除，或者能被400整除，那么这个年份就是闰年- 提示用户输入一个年份，并返回是否是闰年- 提示用户输入一个数字，判断其是否为水仙花数<jupyter_code>year=eval(input('输入年份'))
if ((year%4==0) and (year%100!=0)) or(year%400==0):
    print('是闰年')
else:
    print('为平年')
year=eval(input('输入年份'))
if ((year%4==0) and (year%100!=0)) or(year%400==0):
    print('是闰年')
else:
    print('不是闰年')
x=eval(input('输入数'))
bai=x//100
shi=x//10%10
ge=x%10

if bai**3+shi**3+ge**3==x:
    print('是水仙花数')
else:
    print('不是水仙花数')

for i in range(100,999):
    bai=i//100
    shi=i//10%10
    ge=i%10
    
    if i==bai**3+shi**3+ge**3:
        print(i,'水仙花')<jupyter_output>153 水仙花
370 水仙花
371 水仙花
407 水仙花<jupyter_text>实例研究：彩票![](../Photo/41.png)<jupyter_code>number = random.randint(10,99)
print(number)
N = input('>>')
number_shi = number // 10
number_ge = number % 10

if N[0] == '0':
    N_shi = 0
else:
    N_shi = int(N) // 10
    N_ge = int(N) % 10

if number == int(N):
    print('10000')
#elif (number_shi == N_shi or number_shi==N_ge) and (number_ge == N_shi or number_ge==N_ge)
elif number_shi + number_ge == N_shi + N_ge:
    print('3000')
elif (number_ge == N_ge or number_ge == N_shi) or (number_shi == N_ge or number_shi == N_shi):
    print('1000')<jupyter_output>29
>>29
10000<jupyter_text>Homework- 1![](../Photo/42.png)<jupyter_code>a=eval(input('输入系数'))
b=eval(input('输入系数'))
c=eval(input('输入系数'))
d=b**2-4*a*c
r1=(-b+pow(b**2-4*a*c,1/2))/2*a
r2=(-b-pow(b**2-4*a*c,1/2))/2*a
if d>0:
    print(r1 ,'and',r2)
elif d==0:
    print(r1)
elif d<0:
    print('The equation has no real roots')<jupyter_output>输入系数1.0
输入系数2.0
输入系数1
-1.0<jupyter_text>- 2![](../Photo/43.png)<jupyter_code>import random
a=random.randrange(0,100)
b=random.randrange(0,100)
c=a+b
x=eval(input('请输入两个数之和'))
if x==c:
    print('true')
else:
    print('false')<jupyter_output>请输入两个数之和85
false<jupyter_text>- 3![](../Photo/44.png)<jupyter_code>today=eval(input('请输入0-6之间的整数'))
future=eval(input('请输入未来天数'))
if today==0:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==1:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==2:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==3:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==4:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==5:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)
if today==6:
    week=(today+future)%7
    print('today is ',today,'and the future day is',week)<jupyter_output>请输入0-6之间的整数1
请输入未来天数3
today is  1 and the future day is 4<jupyter_text>- 4![](../Photo/45.png)<jupyter_code>x,y,z=eval(input('请输入三个整数'))
if x<y<z:
    print(x,y,z)
if x<z<y:
    print(x,z,y)
if y<x<z:
    print(y,x,z)
if y<z<x:
    print(y,z,x)
if z<x<y:
    print(z,x,y)
if z<y<x:
    print(z,y,x)<jupyter_output>请输入三个整数5,6,2
2 5 6<jupyter_text>- 5![](../Photo/46.png)<jupyter_code>weight,price=eval(input('请输入大米的质量和价格'))
weight1,price1=eval(input('请输入大米的质量和价格'))
x=price/weight
y=price1/weight1
if x>y:
    print('第二种大米价格更好')
else:
    print('第一种大米价格更好')<jupyter_output>请输入大米的质量和价格50,24.59
请输入大米的质量和价格25,11.99
第二种大米价格更好<jupyter_text>- 6![](../Photo/47.png)<jupyter_code>year=eval(input('请输入年份'))
month=eval(input('请输入月份'))
if ((year%4==0) and (year%100!=0)) or(year%400==0):
    if month<=7:
        if month%2==0:
            if month==2:
                print(year,'年',month,'月','有29天')
            else:
                print(year,'年',month,'月','有30天')
        else:
             print(year,'年',month,'月','有31天')
    else:
        if month%2==0:
            print(year,'年',month,'月','有31天')
        else:
            print(year,'年',month,'月','有30天')
else:
    if month<=7:
        if month%2==0:
            if month==2:
                print(year,'年',month,'月','有28天')
            else:
                print(year,'年',month,'月','有30天')
        else:
             print(year,'年',month,'月','有31天')
    else:
        if month%2==0:
            print(year,'年',month,'月','有31天')
        else:
            print(year,'年',month,'月','有30天')

month = eval(input('输入月份'))
year = eval(input('输入年份'))
if ((year%4==0) and (year%100!=0)) or (year%400==0):
    if month<=7:
        if month%2==0:
            if month==2:
                print(year,'年',month,'月','有29天')
            else:
                print(year,'年',month,'月','有30天')
        else:
            print(year,'年',month,'月','有31天')
    else:
        if month%2==0:
            print(year,'年',month,'月','有31天')
        else:
            print(year,'年',month,'月','有30天')
else :
    if month<=7:
        if month%2==0:
            if month==2:
                print(year,'年',month,'月','有28天')
            else:
                print(year,'年',month,'月','有30天')
        else:
            print(year,'年',month,'月','有31天')
    else:
        if month%2==0:
            print(year,'年',month,'月','有31天')
        else:
            print(year,'年',month,'月','有30天')<jupyter_output>输入月份3
输入年份2005
2005 年 3 月 有31天<jupyter_text>- 7![](../Photo/48.png)<jupyter_code>x=random.randint(0,1)
y=eval(input('请输入一个猜测值'))
if x==y:
    print('true')
else:
    print('false')<jupyter_output>请输入一个猜测值1
false<jupyter_text>- 8![](../Photo/49.png)<jupyter_code>import random

computer=random.randint(0,2)
me=eval(input('请输如0，1，2中的一个数字'))
if me<computer:
    print('you loss')
if me>computer:
    print('you won')
if me==computer:
    print('lt is a draw')<jupyter_output>请输如0，1，2中的一个数字2
you won<jupyter_text>- 9![](../Photo/50.png)<jupyter_code>import math
year=eval(input('请输入年份'))
month=eval(input('请输入月份 '))
today=eval(input('请输入某天'))
if month>=3:
    j=int(year/100)
    k=int(year%100)
    h = (today+((26*(month+1))/10)+k+(k/4)+(j/4)+5*j)%7
    d=math.floor(h)
    if d == 0:
        print('day of the week is 六')
    if d == 1:
        print('day of the week is 日')
    if d == 2:
        print('day of the week is 一')
    if d == 3:
        print('day of the week is 二')
    if d == 4:
        print('day of the week is 三')
    if d == 5:
        print('day of the week is 四')
    if d == 6:
        print('day of the week is 五')
if month==1:
    month=13
    j=int((year-1)/100)
    k=int((year-1)%100)
    h = int((today+((26*(month+1))/10)+k+(k/4)+(j/4)+5*j)%7)
    d=math.floor(h)
    if d == 0:
        print('day of the week is 六')
    if d == 1:
        print('day of the week is 日')
    if d == 2:
        print('day of the week is 一')
    if d == 3:
        print('day of the week is 二')
    if d == 4:
        print('day of the week is 三')
    if d == 5:
        print('day of the week is 四')
    if d == 6:
        print('day of the week is 五')
if month==2:
    month=14
    j=int((year-1)/100)
    k=int((year-1)%100)
    h=int((today+((26*(month+1))/10)+k+(k/4)+(j/4)+5*j)%7)
    d=math.floor(h)
    if d == 0:
        print('day of the week is 六')
    if d == 1:
        print('day of the week is 日')
    if d == 2:
        print('day of the week is 一')
    if d == 3:
        print('day of the week is 二')
    if d == 4:
        print('day of the week is 三')
    if d == 5:
        print('day of the week is 四')
    if d == 6:
        print('day of the week is 五')<jupyter_output>请输入年份2013
请输入月份 1
请输入某天25
day of the week is 五<jupyter_text>- 10![](../Photo/51.png)<jupyter_code>import random
x=random.randint(1,13)
y=random.randint(14,17)
if x==1:
    x='Ace'
if x==11:
    x='Jack'
if x==12:
    x='Queen'
if x==13:
    x='King'
elif y==14:
    y='fangkuai'
elif y==15:
    y='heitao'
elif y==16:
    y='meihua'
elif y==17:
    y='honggtao'
print(y,x)<jupyter_output>heitao 7<jupyter_text>- 11![](../Photo/52.png)<jupyter_code>a=eval(input('请输入三个整数'))
b=eval(input('请输入三个整数'))
c=eval(input('请输入三个整数'))
if a==c:
    print('是回文数')
else:
    print('不是回文数')
x=eval(input('请输入三位整数'))
if x%10==x//100:
    print('是回文数')
else:
    print('不是回文数')<jupyter_output>请输入三位整数212
是回文数<jupyter_text>- 12![](../Photo/53.png)<jupyter_code>a,b,c=eval(input('请输入三角形三个边'))
d=a+b+c
if (a+b>c) and abs(a-b)<c:
    print('周长为',d)
else:
    print('输入是非法的')
9<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20335259174871836, 'fraction_numerical': 0.048661404508096674, 'mean_word_length': 3.351983002832861, 'pattern_counts': {'":': 0, '<': 101, '<?xml version=': 0, '>': 88, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '22', 'dir': 'jupyter-structured-clean-dedup', 'id': '97160', 'license': 'Apache-2.0', 'n_tokens_mistral': 6456, 'n_tokens_neox': 6407, 'n_words': 931, 'path': '7.18.ipynb', 'repo_name': 'cyslime/python1', 'size': '12289'}