<jupyter_start><jupyter_text>选择 布尔类型、数值和表达式![](../Photo/33.png)- 注意：比较运算符的相等是两个等号，一个等到代表赋值- 在Python中可以用整型0来代表False，其他数字来代表True- 后面还会讲到 is 在判断语句中的用发  字符串的比较使用ASCII值  Markdown - https://github.com/younghz/Markdown  EP:- - 输入一个数字，判断其实奇数还是偶数  产生随机数字- 函数random.randint(a,b) 可以用来产生一个a和b之间且包括a和b的随机整数 产生一个随机数，你去输入，如果你输入的数大于随机数，那么就告诉你太大了，反之，太小了，然后你一直输入，知道它满意为止   其他random方法- random.random 返回0.0到1.0之间前闭后开区间的随机浮点- random.randrange(a,b) 前闭后开  EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字的和，并判定其是否正确- 进阶:写一个随机序号点名程序  if语句- 如果条件正确就执行一个单向if语句，亦即当条件为真的时候才执行if内部的语句- Python有很多选择语句:> - 单向if   - 双向if-else  - 嵌套if  - 多向if-elif-else  - 注意：当语句含有子语句的时候，那么一定至少要有一个缩进，也就是说如果有儿子存在，那么一定要缩进- 切记不可tab键和space混用，单用tab 或者 space- 当你输出的结果是无论if是否为真时都需要显示时，语句应该与if对齐<jupyter_code>nianling = eval(input('>>:'))
yanzhi = input('是否帅:[y/n]')
laopo = input('是否有:[y/n]')
if nianling < 28:
    print('年轻')
    if yanzhi == 'y':
        print('帅')
        if laopo == [y]:
            print('有老婆，回家的诱惑')
        else:
            print('没有老婆，马上结婚')
    else:
        print('不帅')
else:
    print('拜拜')
   
     
            

age<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)<jupyter_code>year = eval(input('请输入年份：'))
if year % 12 == :
    res
elif year % 12 == :        
elif year % 12 == :
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
elif year % 12 == :    
if xxx:
    
if xxx:
    
if xxx:
    
if xxx:
    
if xxx:
    
if xxx:<jupyter_output><empty_output><jupyter_text>EP：- 提示用户输入一个年份，然后显示表示这一年的动物![](../Photo/36.png)- 计算身体质量指数的程序- BMI = 以千克为单位的体重除以以米为单位的身高的平方![](../Photo/37.png)<jupyter_code>tz = eval(input('>>'))
sg = eval(input('>>'))
BMI = tz/sg**2
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>>>57
>>1.52
标准<jupyter_text>逻辑运算符![](../Photo/38.png) ![](../Photo/39.png)![](../Photo/40.png)  EP：- 判定闰年：一个年份如果能被4整除但不能被100整除，或者能被400整除，那么这个年份就是闰年- 提示用户输入一个年份，并返回是否是闰年- 提示用户输入一个数字，判断其是否为水仙花数<jupyter_code>year = eval(input('请输入年份：'))
if year % 400 ==0:
    print('闰年')
else:
    print('平年')
year = eval(input('请输入年份：'))
if year % 4 ==0 and year % 100 != 0:
    print('闰年')
else:
    print('平年')<jupyter_output>请输入年份：2000
平年<jupyter_text>实例研究：彩票![](../Photo/41.png)  Homework- 1![](../Photo/42.png)<jupyter_code>a,b,c= eval(input('enter a,b,c:'))
pbs = b**2-4*a*c
r1 = (-b + (pbs)**(1/2))/2*a
r2 = (-b - (pbs)**(1/2))/2*a
if pbs > 0:
    print('the root are', r1,r2)
if pbs == 0:
    print('the root is',r1)
if pbs < 0:
    print('the equation has no real roots')<jupyter_output>enter a,b,c:1,2.0,1
the root is -1.0<jupyter_text>- 2![](../Photo/43.png)<jupyter_code>import random
sum = eval(input('请输入一个数:'))
shu1 = random.randint(0,100)
shu2 = random.randint(0,100)
if sum == shu1 +shu2:
    print('真')
else:
    print('假')<jupyter_output>请输入一个数:87
假<jupyter_text>- 3![](../Photo/44.png)<jupyter_code>today = eval(input("enter today's day:"))
tianshu = eval(input("enter the number of days elapsed since today:"))
day = (today + tianshu)%7
if day==0:
    print("today is ",today,"and the future day is Sunday")
elif day==1:
    print("today is ",today,"and the future day is Monday")
elif day==2:
    print("today is ",today,"and the future day is Tuesday")
elif day==3:
    print("today is ",today,"and the future day is Wednesday")
elif day==4:
    print("today is ",today,"and the future day is Thursday")
elif day==5:
    print("today is ",today,"and the future day is Friday")
elif day==6:
    print("today is ",today,"and the future day is Saturday")<jupyter_output>enter today's day:1
enter the number of days elapsed since today:3
today is  1 and the future day is Thursday<jupyter_text>- 4![](../Photo/45.png)<jupyter_code>a,b,c = eval(input('请输入三个整数a,b,c:'))
if a< b < c:
    print(a,b,c)
elif a< c < b:
    print(a,c,b)
elif c< b < a:
    print(c,b,a)
elif b< a < c:
    print(b,a,c)
elif c< a < b:
    print(c,a,b)
elif b< c < a:
    print(b,c,a)<jupyter_output>请输入三个整数a,b,c:3,1,8
1 3 8<jupyter_text>- 5![](../Photo/46.png)<jupyter_code>price1,package1 = eval(input('enter weight and price for package 1:'))
price2,package2 = eval(input('enter weight and price for package 2:'))
jiage1 = package1/price1
jiage2 = package2/price2
if jiage1> jiage2:
    print('Package 2 has the better price')
else:
    print('Package 1 has the better price')<jupyter_output>enter weight and price for package 1:50,24.59
enter weight and price for package 2:25,11.99
Package 2 has the better price<jupyter_text>- 6![](../Photo/47.png)<jupyter_code>month,year= eval(input('请输入月份和年份:'))
if year % 4 ==0 and year % 100 != 0 and month ==2:
    print('闰年',year,month,'29天')
else:
    print('平年')
    
if month in(1,3,5,7,8,10,12):
    print(month,'31天')
else:
    print(month,'28天')
    print(month,'29天')
mon,year = eval(input('输入月份,输入年份：'))
if (year % 100 !=0 and year % 4==0 or year % 400==0):
    print(year,'年是闰年')
else:
    print(year,'年是平年')
if mon in (1,3,5,7,8,10,12):
    print('这个月有31天')
elif mon == 2:
    print('29天')
else:
    print('28天')
    print('30天')<jupyter_output><empty_output><jupyter_text>- 7![](../Photo/48.png)<jupyter_code>a = 1
b = 0
c = eval(input('输入一个猜测值：'))
if c == a:
    print("正确")
if c == b:
    print("错误")<jupyter_output><empty_output><jupyter_text>- 8![](../Photo/49.png)<jupyter_code>s = 0
r = 1
p = 2
a = eval(input('scissor(0),rock(1),paper(2):'))
if a == s:
    print('The computer is paper.You are scissor.The computer won'or 'The computer is scissor.You are scissor too.It is a draw.'or 'The computer is rock.You are scissor.The computer won')
elif a == r:
    print('The computer is paper.You are rock.The computer won'or 'The computer is scissor.You are rock.You won.'or 'The computer is rock.You are rock too.It is a draw')
elif a == p:
    print('The computer is paper.You are paper too.It is a draw'or 'The computer is scissor.You are paper.The computer won.'or 'The computer is rock.You are paper.You won')<jupyter_output><empty_output><jupyter_text>- 9![](../Photo/50.png) - 10![](../Photo/51.png)<jupyter_code>a = 'Ace'
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
i = 9
k = 10
l = str('Jack')
m = str('Queen')
n = str('King')
o = str('meihua')
p = str('hongtao')
q = str('fangkuai')
r = str('heitao')
s = str(input('请选出一张牌：'))
if s==a or s==b or s==c or s==d or s==e or s==f or s==g or s==h or s==i:
    print('The card you picked is the',a or b or c or d or e or f or g or h or i)<jupyter_output><empty_output><jupyter_text>- 11![](../Photo/52.png)<jupyter_code>num = int(eval(input('输入一个数：')))
num = str(num)
if num [:]== num [::-1]:
    print(num,'是回文数')
else:
    print(num,'不是回文数')<jupyter_output><empty_output><jupyter_text>- 12![](../Photo/53.png)<jupyter_code>a,b,c = eval(input("输入三边的长度："))
d = a+b+c
if (a+b>c and a+c>b and b+c>a):
    print('The perimeter is:',d)
else:
    print('这个输入是非法的')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18469621446854373, 'fraction_numerical': 0.04176209079886838, 'mean_word_length': 3.95263509006004, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 70, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '31581', 'license': 'Apache-2.0', 'n_tokens_mistral': 3821, 'n_tokens_neox': 3748, 'n_words': 707, 'path': '7.18.ipynb', 'repo_name': 'LIUJINCHAO1/mysql', 'size': '7423'}