<jupyter_start><jupyter_text>选择 布尔类型、数值和表达式![](../Photo/33.png)- 注意：比较运算符的相等是两个等号，一个等到代表赋值- 在Python中可以用整型0来代表False，其他数字来代表True- 后面还会讲到 is 在判断语句中的用发<jupyter_code>a = id(1)
b = id(1)

print(a,b)
# 因为a和b并不是同一个对象
a is b
a = id(1)
b = a
a is b
a = True
b = False
id(True)
a == b
a is b<jupyter_output><empty_output><jupyter_text>字符串的比较使用ASCII值<jupyter_code>a = "jokar"
b = "jokar"
a > b<jupyter_output><empty_output><jupyter_text>Markdown - https://github.com/younghz/Markdown 肯定会给发数据划分啊 $\sum_{j=1}^{N}x_{j}$  EP:- - 输入一个数字，判断其实奇数还是偶数  产生随机数字- 函数random.randint(a,b) 可以用来产生一个a和b之间且包括a和b的随机整数<jupyter_code>import random
random.randint(0,1)
if condition:
    do someething
else:
    other
for iter_ in xxx:
    do something

age = 10
Joker = eval(input('Name'))
print(Joker)<jupyter_output>Nameage
10<jupyter_text>产生一个随机数，你去输入，如果你输入的数大于随机数，那么就告诉你太大了，反之，太小了，然后你一直输入，知道它满意为止<jupyter_code>number =random.randint(0,5)
for i in range(5):
    input_  = eval(input('>>'))
    if input_ > number:
        print('太大啦')
    if input_ < number:
        print('太小啦')
    if number == input_:
        print('正好')
        break
for i in range(5):
    print(i)<jupyter_output>0
1
2
3
4<jupyter_text>其他random方法- random.random 返回0.0到1.0之间前闭后开区间的随机浮点- random.randrange(a,b) 前闭后开<jupyter_code>random.random()
import matplotlib.pyplot as plt
image=plt.imread('/Users/huwang/Downloads/cat.jpeg')
print(image*random.random())
plt.imshow(image)<jupyter_output>[[[41.86550961 15.53771491 17.69573087]
  [47.04474791 22.01176278 21.58015959]
  [52.22398621 28.48581066 25.46458832]
  ...
  [95.3843054  93.65789263 63.01406601]
  [95.3843054  93.65789263 63.01406601]
  [94.52109902 92.79468625 61.28765324]]

 [[42.2971128  15.9693181  18.12733406]
  [47.04474791 22.01176278 21.58015959]
  [52.22398621 28.48581066 25.46458832]
  ...
  [95.3843054  93.65789263 63.01406601]
  [95.3843054  93.65789263 63.01406601]
  [94.52109902 92.79468625 61.28765324]]

 [[42.72871599 16.83252448 17.69573087]
  [47.4763511  22.44336598 22.01176278]
  [52.65558941 28.91741385 25.89619151]
  ...
  [95.3843054  93.65789263 63.01406601]
  [95.3843054  93.65789263 63.01406601]
  [94.95270221 93.22628944 62.58246282]]

 ...

 [[65.60368516 67.33009793 56.54001813]
  [71.21452666 73.37254261 63.4456692 ]
  [79.4149873  83.29941603 75.09895538]
  ...
  [28.91741385 15.10611171 24.16977874]
  [29.34901705 15.9693181  23.73817555]
  [29.78062024 18.99054044 28.05420747]]

 [[...]<jupyter_text>EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字的和，并判定其是否正确- 进阶:写一个随机序号点名程序<jupyter_code>number_1 = random.randrange(0,10)
number_2 = random.randrange(0,10)

while 1:
    sum_ = eval(input('>>'))
    if sum_ == (number_1 + number_2):
        print('Congratulations! Correct~')
    else:
        print('Sorry~SB.')<jupyter_output>>>2
Sorry~SB.
>>3
Sorry~SB.
>>4
Sorry~SB.
>>5
Sorry~SB.
>>6
Sorry~SB.<jupyter_text>if语句- 如果条件正确就执行一个单向if语句，亦即当条件为真的时候才执行if内部的语句- Python有很多选择语句:> - 单向if   - 双向if-else  - 嵌套if  - 多向if-elif-else  - 注意：当语句含有子语句的时候，那么一定至少要有一个缩进，也就是说如果有儿子存在，那么一定要缩进- 切记不可tab键和space混用，单用tab 或者 space- 当你输出的结果是无论if是否为真时都需要显示时，语句应该与if对齐<jupyter_code>input_  = eval(input('>>'))
if input_ > number:
    print('太大啦')
if input_ < number:
    print('太小啦')
if number == input_:
    print('正好')
print('不要灰心')<jupyter_output>>>1
正好
不要灰心<jupyter_text>李文浩相亲测试树      年龄   老      年轻   拜拜                           帅               否    是           考虑一下     老婆                    没有     有                 马上结婚     回家的诱惑                 代码写不出来的立马分手,从此社会上有多出一个渣男/渣女.<jupyter_code>age = input('年轻嘛[y/n]')
if age == 'y':
    handsome = input('帅否[y/n]')
    if handsome == 'y':
        wife = input('有没有老婆[y/n]')
        if wife == 'y':
            print('回家的诱惑')
        else:
            print('立马结婚')
    else:
        print('考虑一下')
else:
    print('拜拜~')<jupyter_output>年轻嘛[y/n]y
帅否[y/n]y
有没有老婆[y/n]y
回家的诱惑<jupyter_text>EP：- 用户输入一个数字，判断其实奇数还是偶数- 进阶：可以查看下4.5实例研究猜生日  双向if-else 语句- 如果条件为真，那么走if内部语句，否则走else内部语句  EP：- 产生两个随机整数number1和number2，然后显示给用户，使用户输入数字，并判定其是否正确,如果正确打印“you‘re correct”，否则打印正确错误  嵌套if 和多向if-elif-else![](../Photo/35.png)<jupyter_code>if score >= 80:
    gread = 'B'
elif score>=90:
    gread = 'A'<jupyter_output><empty_output><jupyter_text>EP：- 提示用户输入一个年份，然后显示表示这一年的动物![](../Photo/36.png)- 计算身体质量指数的程序- BMI = 以千克为单位的体重除以以米为单位的身高的平方![](../Photo/37.png)<jupyter_code>tizhong  = eval(input('体重'))
shengao = eval(input('身高'))
BMI = tizhong / shengao ** 2
if BMI<18.5 :
    print('超清')
elif 18.5<=BMI<25 :
    print('标准')
elif 25<=BMI<30 :
    print('超重')
else:
    print('超级无敌胖')<jupyter_output>体重500
身高10000
超清<jupyter_text>逻辑运算符![](../Photo/38.png) ![](../Photo/39.png)![](../Photo/40.png)  EP：- 判定闰年：一个年份如果能被4整除但不能被100整除，或者能被400整除，那么这个年份就是闰年- 提示用户输入一个年份，并返回是否是闰年- 提示用户输入一个数字，判断其是否为水仙花数  实例研究：彩票![](../Photo/41.png)<jupyter_code>import random
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')
a = "05"
a[0]
05 // 10
Number = eval(input('>>'))

bai = Number // 100
shi = Number // 10 % 10
ge = Number % 10

if bai**3 + shi **3 + ge **3 == Number:
    print('水仙花')
else:
    print('不是水仙花')
223 // 10<jupyter_output><empty_output><jupyter_text>Homework- 1![](../Photo/42.png)<jupyter_code>a,b,c = map(float,input('Enter a,b,c：').split(','))
import math
if b*b - 4*a*c > 0:
    r1 = (-b + math.sqrt(b*b - 4*a*c))/(2*a)
    r2 = (-b - math.sqrt(b*b - 4*a*c))/(2*a)
    print (r1,r2)
elif b*b - 4*a*c == 0:
    print(r1)
else:
    print('The equation has no real roots')<jupyter_output>Enter a,b,c：1,2,3
The equation has no real roots<jupyter_text>- 2![](../Photo/43.png)<jupyter_code>import random
num_1 = random.randint(0,100)
num_2 = random.randint(0,100)
num_1 = int(input('请输入一个数:'))
num_2 = int(input('请输入一个数:'))
r=int(input('请输入两个数的和的正确答案：'))
if num_1 + num_2==r:
    print('true')
else:
    print('false')<jupyter_output>请输入一个数:98
请输入一个数:1
请输入两个数的和的正确答案：99
true<jupyter_text>- 3![](../Photo/44.png)<jupyter_code>t_ = int(input("Enter today\'s day:"))
d_ = int(input("Enter the number of days elapsed since today:"))
d_=(d_+t_)%7
week = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
print("Today is {} and the future day is {} ".format(week[t_],week[d_]))<jupyter_output>Enter today's day:0
Enter the number of days elapsed since today:31
Today is Sunday and the future day is Wednesday<jupyter_text>- 4![](../Photo/45.png)<jupyter_code>x = int(input('x='))
y = int(input('y='))
z = int(input('z='))
if x>y>z:
    print(x,y,z)
elif x>z>y:
    print(x,z,y)
elif y>x>z:
    print(y,x,z)
elif y>z>x:
    print(y,z,x)
elif z>x>y:
    print(z,x,y)
else: 
    print(z>y>x)<jupyter_output>x=5
y=1
z=3
5 3 1<jupyter_text>- 5![](../Photo/46.png)<jupyter_code>w_1,p_1=map(float,input('Enter weight and price for package:').split(','))
w_2,p_2=map(float,input('Enter weight and price for package:').split(','))
if p_1>p_2: 
    print('Package 2 has the better price')
else:
    print('Package 2 has the better price')<jupyter_output>Enter weight and price for package:50,24.59
Enter weight and price for package:25,11.99
Package 2 has the better price<jupyter_text>- 6![](../Photo/47.png)<jupyter_code>month,year=map(int,input('Enter month and year:').split(','))
d1=1,3,5,7,8,10,12
d2=4,6,9,11
if month in d1:
    print('%d月有31天'%month)
if month==2:
    if  (year % 4 ==0 and year % 100 !=0 ) or (year % 400 == 0):
        print('二月有29天')
    else:
        print('二月有28天')
if month in d2:
    print('%d月有30天'%month)<jupyter_output>Enter month and year:2,2000
二月有29天<jupyter_text>- 7![](../Photo/48.png)<jupyter_code>z=input('弹起面n=正面，m=反面：')
r='n'
if r==z:
    print(True)
else:
    print(False)<jupyter_output>弹起面n=正面，m=反面：m
False<jupyter_text>- 8![](../Photo/49.png)<jupyter_code>import random
s = random.randrange(1,4)
r = int(input('石头剪刀布：'))
if r == s:
    print("The computer is {}. You are {} too.It is a draw.".format(s,r))
elif (r == 1 and s == 2) or (r == 2 and s == 3) or (r == 3 and s == 1):
    print("The computer is {}. You are {}.You won.".format(s,r))
else:
    print("The computer is {}. You are {} too.You lose.".format(s,r))<jupyter_output>石头剪刀布：2
The computer is 2. You are 2 too.It is a draw.<jupyter_text>- 9![](../Photo/50.png)<jupyter_code>n = int(input("Enter year(e.g., 2008)"))
y = int(input("Enter month: 1-12:"))
t = int(input("Enter the day of month: 1-31"))
if y == 1:
    y = 13
    n = n - 1
if y == 2:
    y = 14
    n = n - 1
m = (t + ((26 * (y + 1)) // 10) + n % 100 + n % 100 / 4 + n // 100 / 4 + 5 * n // 100) % 7
print("Day of the week is {}".format(m))<jupyter_output>Enter year(e.g., 2008)2012
Enter month: 1-12:5
Enter the day of month: 1-3112
Day of the week is 0.0<jupyter_text>- 10![](../Photo/51.png)<jupyter_code>import numpy as np 

r =np.random.choice(['1','2','3','4','5','6','7','8','9','10','jack','Queen','King'])
r_1=np.random.choice(['Spade','Diamond','Club','Heart'])
print('The card you pick is the {} of {}'.format(r,r_1))<jupyter_output>The card you pick is the 8 of Club<jupyter_text>- 11![](../Photo/52.png)<jupyter_code>m = int(input('Enter a three-digit integer:'))
g = m % 10
b = m // 10 // 10
if g == b:
    print('m is a palindrome')
else:
    print('m is not a palindrome')<jupyter_output>Enter a three-digit integer:121
m is a palindrome<jupyter_text>- 12![](../Photo/53.png)<jupyter_code>x,y,z =map(float,input('Enter three edges:').split(','))
import math
if x+y>z and x+z>y and z+y>x:
     print('周长是：%.0f' %(x+y+z))
   
else:
     print('不能构成三角形')<jupyter_output>Enter three edges:1,1,1
周长是：3
{'fraction_non_alphanumeric': 0.18406148867313915, 'fraction_numerical': 0.11134708737864078, 'mean_word_length': 4.014705882352941, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 119, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '23', 'dir': 'jupyter-structured-clean-dedup', 'id': '22453', 'license': 'Apache-2.0', 'n_tokens_mistral': 5612, 'n_tokens_neox': 5065, 'n_words': 828, 'path': '7.18.ipynb', 'repo_name': 'JKVJK/Test', 'size': '9888'}