<jupyter_start><jupyter_text>选择 布尔类型、数值和表达式![](../Photo/33.png)- 注意：比较运算符的相等是两个等号，一个等到代表赋值- 在Python中可以用整型0来代表False，其他数字来代表True- 后面还会讲到 is 在判断语句中的用发<jupyter_code>a = 1
b = "2"
a == b
0 is 1<jupyter_output><empty_output><jupyter_text>字符串的比较使用ASCII值<jupyter_code>a = "Wodet"
b = "lalal"
a > b<jupyter_output><empty_output><jupyter_text>Markdown - https://github.com/younghz/Markdown x = 2x - 1  EP:- - 输入一个数字，判断其实奇数还是偶数<jupyter_code>int(True)
bool(0)
x = eval(input("x:>>"))
if (x%2 == 0):
    print("偶数")
if x%2 == 1:
    print("奇数")
x = eval(input(">>"))
if x%2 == 0::
    print("偶数")
else
    print("奇数")<jupyter_output><empty_output><jupyter_text>产生随机数字- 函数random.randint(a,b) 可以用来产生一个a和b之间且包括a和b的随机整数<jupyter_code>import random
random.randint(1，9)
y = eval(input("请输入一个数字"))
if y > x:
    print("太大了")
if y < x:
    print("太小了")
if y ==x:
    print("正确")<jupyter_output>请输入一个数字5
正确<jupyter_text>产生一个随机数，你去输入，如果你输入的数大于随机数，那么就告诉你太大了，反之，太小了，然后你一直输入，知道它满意为止   其他random方法- random.random 返回0.0到1.0之间前闭后开区间的随机浮点- random.randrange(a,b) 前闭后开<jupyter_code>random.randrange(3,5)<jupyter_output><empty_output><jupyter_text>EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字的和，并判定其是否正确- 进阶:写一个随机序号点名程序<jupyter_code>number1 = random.randrange(1,9)
number2 = random.randrange(1,9)
print(number1)
print(number2)
n = eval(input("请输入数字和"))

if n == (number1 + number2):
    print("正确")
else:
    print("错误")
for i in range(5):
    x = eval(input("x"))
    if x == (number1 + number2):
        print("正确")
        break
    else:
        print("错误")
n = eval(input("a"))

for i in range(2,5):
    if x%i == 0:
        print(i,"可以整除")
#有冒号需要缩进四个空格<jupyter_output><empty_output><jupyter_text>if语句- 如果条件正确就执行一个单向if语句，亦即当条件为真的时候才执行if内部的语句- Python有很多选择语句:> - 单向if   - 双向if-else  - 嵌套if  - 多向if-elif-else  - 注意：当语句含有子语句的时候，那么一定至少要有一个缩进，也就是说如果有儿子存在，那么一定要缩进- 切记不可tab键和space混用，单用tab 或者 space- 当你输出的结果是无论if是否为真时都需要显示时，语句应该与if对齐<jupyter_code>money = input("是否有钱[y/n]")
if money == "y":
    print("再问一个问题")
    handsome = input("帅不帅[y/n]")
    if handsome == "y":
        print("非常关键的一个问题")
        wife = input("是否有妻子[y/n]")
        if wife == "y":
            print("不拒绝")
        else:
            print("马上结婚")
    else:
        print("考虑一下")
else:
    print("Gun~")
#if condiiton:
    #if condition:
        #do something
    #else:
        #other
    #do something
#else:
    #other
score = 80
if score >= 90:
    grad = "A"
elif score >= 80:
    grad = "B"
elif score >= 70:
    grad = "D"
    
print(grad)
#elif,成立的话其他一个不走
money = input("money[1/0]")
handsome = input("handsome[1/0]")
wife = input("wife[1/0]")

x = money + handsome + wife
if x == 3:
    print("马上结婚")
elif x == 2:
    if 
    print("考虑一下")
    
elif x = 1:
    print("不拒绝")
elif x == 0:
    print("gun")
print("grade")
#if和elif必须出现一次<jupyter_output><empty_output><jupyter_text>EP：- 用户输入一个数字，判断其实奇数还是偶数- 进阶：可以查看下4.5实例研究猜生日  双向if-else 语句- 如果条件为真，那么走if内部语句，否则走else内部语句  EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字，并判定其是否正确,如果正确打印“you‘re correct”，否则打印正确错误  嵌套if 和多向if-elif-else![](../Photo/35.png)  EP：- 提示用户输入一个年份，然后显示表示这一年的动物![](../Photo/36.png)- 计算身体质量指数的程序- BMI = 以千克为单位的体重除以以米为单位的身高的平方![](../Photo/37.png)<jupyter_code>year = eval(input("year"))
x = year % 1
if x ==0:
    print("猴子")
elif x ==1:
    print("鸡")
elif x ==2:
    print("狗")
elif x ==3:
    print("猪")
elif x ==4:
    print("鼠")
elif x ==5:
    print("牛")
elif x ==6:
    print("虎")
elif x ==7:
    print("兔")
elif x ==8:
    print("龙")
elif x ==9:
    print("蛇")
elif x ==10:
    print("马")
elif x ==11:
    print("羊")
身高 = eval(input("身高"))
体重 = eval(input("体重"))
BMI = 体重 / 身高**2
if BMI<18.5:
    print("超轻")
elif 18.5<=BMI<25:
    print("标准")
elif 25<=BMI<30:
    print("超重")
else:
    print("超超级胖")<jupyter_output>身高1.71
体重52
超轻<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("平年")
number = eval(input("数字"))
bai = number // 100
shi = number // 10 % 10
ge = number % 10

if bai**3 + shi**3 + ge**3 == number:
    print("水仙花")
n = eval(input("a"))

for i in range(2,5):
    if x%i == 0:
        print(i,"可以整除")<jupyter_output><empty_output><jupyter_text>实例研究：彩票![](../Photo/41.png)  Homework- 1![](../Photo/42.png)<jupyter_code>import math
a = eval(input("a"))
b = eval(input("b"))
c = eval(input("c"))
x = b * b - 4 * a * c
if x > 0:
    r1 = (-b + sqrt.math((b * b) - 4 * a * c)) / 2 * a
    r2 = (-b - sqrt.math((b * b) - 4 * a * c)) / 2 * a
    print("r1,r2")
elif x == 0:
    r3 = (-b + sqrt.math((b * b) - 4 * a * c)) / 2 * a
    print("r3")
elif x < 0:
    print("没有根")<jupyter_output>a1
b2
c3
没有根<jupyter_text>- 2![](../Photo/43.png)<jupyter_code>import random
number1 = random.randint(1,100)
number2 = random.randint(1,100)
n = number1 + number2
x = eval(input("请输入数字和"))
if n == x:
    print("真")
else:
    print("假")<jupyter_output>请输入数字和50
假<jupyter_text>- 3![](../Photo/44.png)<jupyter_code>a = eval(input("今天星期几"))
b = eval(input("几天以后"))
c = (a + b) % 7
if c == 0:
    print("今天是星期日")
else:    
    print("今天星期",c)<jupyter_output>今天星期几3
几天以后3
今天星期 6<jupyter_text>- 4![](../Photo/45.png)<jupyter_code>x = eval(input("请输入一个数字"))
y = eval(input("请再输入一个数字"))
z = eval(input("再输入一个数字"))
list1 = [x,y,z]
list1.sort()
print(list1)<jupyter_output>请输入一个数字5
请再输入一个数字8
再输入一个数字9
[5, 8, 9]<jupyter_text>- 5![](../Photo/46.png)<jupyter_code>x1 = eval(input("请输入第一种包装的重量"))
y1 = eval(input("请输入第一种包装价钱"))
x2 = eval(input("第二种重量"))
y2 = eval(input("第二种价钱"))
z1 = x1 / x2
z2 = y1 / y2
if z1 > 1 and z2 > 1:
    print ("第二种")
if z2 < 1 and z1 < 1:
    print("第一种")<jupyter_output>请输入第一种包装的重量50
请输入第一种包装价钱24.59
第二种重量25
第二种价钱11.99
第二种<jupyter_text>- 6![](../Photo/47.png)<jupyter_code>month = eval(input("请输入月"))
year = eval(input("请输入年"))
if ((year%4==0) and (year%100!=0)) or (year%400==0):
    if month == 2:
        print(year,"年",month,"月份","有28天") 
else:
    if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
        print(year,"年",month,"月份","有31天") 
    elif month == 2:
        print(year,"年",month,"月份","有29天") 
    elif month == 4 or month == 6 or month == 9 or month == 11:
        print(year,"年",month,"月份","有30天")<jupyter_output>请输入月4
请输入年2015
2015 年 4 月份 有30天<jupyter_text>- 7![](../Photo/48.png)<jupyter_code>import random
suiji = random.randint(1,2)
jieguo = eval(input("输入结果"))
if suiji == jieguo:
    print("YES")
else:
    print("NO")<jupyter_output>输入结果2
YES<jupyter_text>- 8![](../Photo/49.png)<jupyter_code>import random
suiji=random.randint(0,2)
chuchu=eval(input("石头=0 剪刀=2 布=1  "))
if chuchu==suiji:
    print("平局")
else:
    if chuchu==0 and suiji==2:
        print("赢了")
    elif chuchu==2 and suiji==0:
        print("输了")
    elif chuchu>suiji:
        print("赢了")
    else:
        print("输了")<jupyter_output>石头=0 剪刀=2 布=1  2
平局<jupyter_text>- 9![](../Photo/50.png) - 10![](../Photo/51.png)<jupyter_code>import random
suiji1 = random.randint(1,4)
suiji2 = random.randint(1,13)
if suiji1 == 1:
    suiji1 = "红桃"
elif suiji1 == 2:
    suiji1 = "梅花"
elif suiji1 == 3:
    suiji1 = "方块"
elif suiji1 == 4:
    suiji1 = "黑桃"

if suiji2 == 1:
    suiji2 = "Ace"
elif suiji2 == 11:
    suiji2 = "Jack"
elif suiji2 == 12:
    suiji2="Queen"
elif suiji2 == 13:
    suiji2 = "King"
print("这张牌是 ",suiji1,suiji2)<jupyter_output>这张牌是  黑桃 Queen<jupyter_text>- 11![](../Photo/52.png)<jupyter_code>n = eval(input("输入一个三位数"))
ge = n % 10
bai = n // 100
if ge == bai:
    print("回文数")
else:
    print("不是回文数")<jupyter_output>输入一个三位数121
回文数<jupyter_text>- 12![](../Photo/53.png)<jupyter_code>a = eval(input("一个边长"))
b = eval(input("一个边长"))
c = eval(input("一个边长"))
if a + b > c and a + c >b and b + c > a:
    y = a + b + c
    print(y)
else:
    print("不合法")<jupyter_output>一个边长1
一个边长1
一个边长1
3
{'fraction_non_alphanumeric': 0.19901564866229177, 'fraction_numerical': 0.04669358909641595, 'mean_word_length': 3.811778992106861, 'pattern_counts': {'":': 3, '<': 77, '<?xml version=': 0, '>': 85, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '20', 'dir': 'jupyter-structured-clean-dedup', 'id': '97720', 'license': 'Apache-2.0', 'n_tokens_mistral': 4373, 'n_tokens_neox': 4422, 'n_words': 674, 'path': '7.18.ipynb', 'repo_name': 'motuoluolalalal/mysql', 'size': '7924'}