<jupyter_start><jupyter_text>选择 布尔类型、数值和表达式![](../Photo/33.png)- 注意：比较运算符的相等是两个等到，一个等到代表赋值- 在Python中可以用整型0来代表False，其他数字来代表True- 后面还会讲到 is 在判断语句中的用发<jupyter_code>chengji = eval(input('请输入分数：'))
if 100>=chengji>=90:
print ('您的成绩为A！')
if 90>chengji>=80:
print ('您的成绩为B！')
if 80>chengji>=70:
print ('您的成绩为C！')
if 70>chengji>=60:
print ('您的成绩为D！')
if 60>chengji:
print ('退学吧！')
import random

random.randint(10,100)
while True:
    shu = eval(input('请输入一个数：'))
if 10>shu:
    print ('您输入的数太小了！')
if 100<shu:
    print ('您输入的数太大了！')<jupyter_output><empty_output><jupyter_text>字符串的比较使用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，然后显示给用户，使用户输入数字的和，并判定其是否正确- 进阶:写一个随机序号点名程序<jupyter_code>import random
suijishu1 = random.randint(0,100)
print (suijishu1)
suijishu2 = random.randint(0,100)
print (suijishu2)
sum = suijishu1+suijishu2
daan = eval(input('请输入正确答案：'))
if daan == sum:
    print ('你好棒棒呦！')
else:
    print ('你真菜！')<jupyter_output>28
41<jupyter_text>if语句- 如果条件正确就执行一个单向if语句，亦即当条件为真的时候才执行if内部的语句- Python有很多选择语句:> - 单向if   - 双向if-else  - 嵌套if  - 多向if-elif-else  - 注意：当语句含有子语句的时候，那么一定至少要有一个缩进，也就是说如果有儿子存在，那么一定要缩进- 切记不可tab键和space混用，单用tab 或者 space- 当你输出的结果是无论if是否为真时都需要显示时，语句应该与if对齐<jupyter_code>import random
nianling = eval(input('请输入年龄：'))
zhangxiang = (input('请输入长相：'))
shouru = (input('请输入收入：'))
gongwuyuan= (input('请输入是否是公务员：'))<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>import random
years = eval(input('请输入一个年份：'))
if years%12 == 0:
    print('猴')
if years%12 == 1:
    print('鸡')
if years%12 == 2:
    print('狗')
if years%12 == 3:
    print('猪')
if years%12 == 4:
    print('鼠')
if years%12 == 5:
    print('牛')
if years%12 == 6:
    print('虎')
if years%12 == 7:
    print('兔')
if years%12 == 8:
    print('龙')
if years%12 == 9:
    print('蛇')
if years%12 == 10:
    print('马')
if years%12 == 11:
    print('羊')<jupyter_output>请输入一个年份：2000
龙<jupyter_text>逻辑运算符![](../Photo/38.png) ![](../Photo/39.png)![](../Photo/40.png)  EP：- 判定闰年：一个年份如果能被4整除但不能被100整除，或者能被400整除，那么这个年份就是闰年- 提示用户输入一个年份，并返回是否是闰年- 提示用户输入一个数字，判断其是否为水仙花数<jupyter_code>import random
years = eval(input('请输入一个年份：'))
if ((years%4) == 0 and (years%100 !=0)) or (years%400 == 0):
    print('该年是闰年！')
else:
    print('该年不是闰年！')
import random
sxh = eval(input('请输入一个3位数：'))
a = sxh%10
b = sxh//10
c = b%10
d = b//10
if a**3+c**3+d**3 == sxh:
    print ('该数是水仙花数')
else:
    print ('该数不是水仙花数')<jupyter_output>请输入一个3位数：153
该数是水仙花数<jupyter_text>实例研究：彩票![](../Photo/41.png)<jupyter_code>import random
num = eval(input('请输入一个两位数：'))
haoma = random.randint(11,19)or(21,29)or(31,39)or(41,49)or(51,59)or(61,69)or(71,79)or(81,89)or(91,99)
if num == haoma:
    print('$10000')
    print (haoma)
else:
    print(haoma)<jupyter_output>请输入一个两位数：98
19<jupyter_text>Homework- 1![](../Photo/42.png)<jupyter_code>import math
a,b,c = eval(input('请输入a，b，c的值'))
if (b**2-4*a*c)>0:
    r1 = ((-b+math.sqrt(b**2-4*a*c))/(2*a))
    r2 = ((-b-math.sqrt(b**2-4*a*c))/(2*a))
    print(r1,r2)
if (b**2-4*a*c)==0:
    r1 = ((-b+math.sqrt(b**2-4*a*c))/(2*a))
    r2 = ((-b-math.sqrt(b**2-4*a*c))/(2*a))
    print(r1)
else:
    print('The equation has no real roots')<jupyter_output>请输入a，b，c的值1,2,3
The equation has no real roots<jupyter_text>- 2![](../Photo/43.png)<jupyter_code>import random
suijishu1 = random.randint(0,100)
suijishu2 = random.randint(0,100)
sum = suijishu1+suijishu2
print (suijishu1)
print (suijishu2)
daan = eval(input('请输入正确答案：'))
if daan == sum:
    print ('你好棒棒呦！')
else:
    print ('你真菜！')<jupyter_output>32
19
请输入正确答案：3232
你真菜！<jupyter_text>- 3![](../Photo/44.png)<jupyter_code>day = eval(input('Enter today is day: '))
since = eval(input('Enter the number of days elapsed since today； '))
today = (day + since)%7
if day == 0:             #判断今天是星期几
    day1 = 'Sunday'
elif day ==1:
    day1 = 'Monday'
elif day ==2:
    day1 = 'Tuesday'
elif day ==3:
    day1 = 'Wednesday'
elif day ==4:
    day1 = 'Thursday'
elif day ==5:
    day1 = 'Friday'
elif day ==6:
    day1 = 'Saturday'

if today == 0:             #判断几天后是星期几
    day2 = 'Sunday'
elif today ==1:
    day2 = 'Monday'
elif today ==2:
    day2 = 'Tuesday'
elif today ==3:
    day2 = 'Wednesday'
elif today ==4:
    day2 = 'Thursday'
elif today ==5:
    day2 = 'Friday'
elif today ==6:
    day2 = 'Saturday'
print('Today is '+str(day1)+' and the future day is '+str(day2))<jupyter_output>Enter today is day: 3
Enter the number of days elapsed since today； 6
Today is Wednesday and the future day is Tuesday<jupyter_text>- 4![](../Photo/45.png)<jupyter_code>a,b,c=eval(input("输入三个整数"))
if a>b:
    t=b
    b=a
    a=t
elif b>c:
    t=c
    c=b
    b=t
elif a>c:
    t=c
    c=a
    a=t
print(str(a),str(b),str(c))<jupyter_output>输入三个整数1,5,2
1 2 5<jupyter_text>- 5![](../Photo/46.png)<jupyter_code>weight1 = eval(input('请输入第一种大米的重量：'))
price1 = eval(input('请输入第一种大米的价格：'))
weight2 = eval(input('请输入第二种大米的重量：'))
price2 = eval(input('请输入第二种大米的价格：'))
if (price1/weight1)>(price2/weight2):
    print ('Package 2 has the better price!')
else:
    print ('Package 1 has the better price!')<jupyter_output>请输入第一种大米的重量：100
请输入第一种大米的价格：100
请输入第二种大米的重量：100
请输入第二种大米的价格：100
Package 1 has the better price!<jupyter_text>- 6![](../Photo/47.png)<jupyter_code>import math
years = eval(input('请输入年份：'))
month = eval(input('请输入月份：'))
if month == (1,3,5,7,8,10,12):
    print (str(years)+'年'+str(month)+'月份有31天')
elif month == (4,6,9,11):
    print (str(years)+'年'+str(month)+'月份有30天')
elif ((years%4) == 0 and (years%100 !=0)):
    print (str(years)+'年'+str(month)+'月份有29天')
else:
    print (str(years)+'年'+str(month)+'月份有28天')<jupyter_output>请输入年份：2018
请输入月份：9
2018年9月份有28天<jupyter_text>- 7![](../Photo/48.png)<jupyter_code>import random
num = eval(input('请输入0或1'))
pc = random.randint(0,1)
if num == pc:
    print('你猜对了')
else:
    print('你猜错了')<jupyter_output>请输入0或11
你猜错了<jupyter_text>- 8![](../Photo/49.png)<jupyter_code>import random
num = eval(input('请输入0，1或2：'))
pc = random.randint(0,2)
if (num-pc==1)or(num==0and(pc==2)):
    print('你赢了')
elif (pc-num==1)or(num==2and(pc==0)):
    print('你输了')
else:
    print('平局')<jupyter_output>请输入0，1或2：0
平局<jupyter_text>- 9![](../Photo/50.png)<jupyter_code>y = eval(input('请输入年份：'))
m = eval(input('请输入月份：'))
q = eval(input('请输入天数：'))
j = y//100//1
k = y%100
if m == 1:
    m = 13
elif m == 2:
    m = 14
h = (q + (26*(m+1))/10//1+k+k/4//1+j/4//1+5*j)%7
if h == 0:
    print ('Day of the week is Saturday')
elif h ==1:
    print ('Day of the week is Sunday')
elif h ==2:
    print ('Day of the week is Monday')
elif h ==3:
    print ('Day of the week is Tuesday')
elif h ==4:
    print ('Day of the week is Wednesday')
elif h ==5:
    print ('Day of the week is Thursday')
elif h ==6:
    print ('Day of the week is Friday')<jupyter_output>请输入年份：2012
请输入月份：5
请输入天数：12
Day of the week is Saturday<jupyter_text>- 10![](../Photo/51.png)<jupyter_code>import random
A=['Ace',2,3,4,5,6,7,8,9,10,'Jack','Queen','King']
ran=random.randint(0,len(A)-1)
B=['Diamond','Heart','Spade','Club']
can=random.randint(0,len(B)-1)
print(str(B[can])+str(A[ran]))<jupyter_output>DiamondJack<jupyter_text>- 11![](../Photo/52.png)<jupyter_code>num = eval(input('请输入一个三位数：'))
a = num%10
b = num//10
c = b%10
d = b//10
if a==d:
    print(str(num)+'是一个回文数')
else:
    print(str(num)+'不是一个回文数')<jupyter_output>请输入一个三位数：323
323是一个回文数<jupyter_text>- 12![](../Photo/53.png)<jupyter_code>a,b,c = eval(input('请输入三角形的三条边长：'))
if (a+b<=c)or(a+c<=b)or(b+c<=a):
    print('这个输入是非法的！')
else:
    print(a+b+c)<jupyter_output>请输入三角形的三条边长：1,1,1
3
{'fraction_non_alphanumeric': 0.20257757757757758, 'fraction_numerical': 0.05980980980980981, 'mean_word_length': 5.02790346907994, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 73, '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': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '615867', 'license': 'Apache-2.0', 'n_tokens_mistral': 4518, 'n_tokens_neox': 4484, 'n_words': 641, 'path': '9.12.ipynb', 'repo_name': 'ningjing957/zuoye', 'size': '7992'}