""" 代码加注释的两种方式: 1.单行注释,用#,用法:单独一行,顶格写;跟在代码后面,与代码两空格; 2.#后边空一格在写内容 3.多行注释,三双或双单引号包裹。 4.快速注释多行代码,ctrl+/ """ # print("程序开始执行") # a = 10 # 定义了一个变量a,并且为其赋值10 # if a > 20: # 条件判断,如果a的值大于20,就执行以下代码块语句 # print("今天中午吃什么?") # print("我订饭了。") # print(a) # else: # if--else,if条件不成立时,执行else以下的代码块 # print("上课时间不能讨论吃饭问题") # print("哈哈哈") # if True: # print("今天星期五,好开心呀!") # print(a) # print("xxx") # print("程序执行结束!") # from this import c # from Tools.scripts.patchcheck import status """ a = 8 if a > 7: print("上课了,大家认真听讲") print("不能玩手机!") else: print("在吃早饭。") 标识符命名规则: 1.由字母下划线、数字、下划线组成; 2.不能以数字开头; 3.不能使用关键字 4见字知意 5.驼峰式:小驼峰,大驼峰 6.单词_单词:推荐 7.区分大小写 """ # a = 10 # A = 20 # print(a) # # 复制当前代码行,快捷键:ctul+d # print(A) # _a = 3 # student_1 = "李小花" # 推荐 # student_2 = "王二狗" # 推荐 # print(student_1, student_2, _a) # firstName = "发" # 小驼峰 # LastName = "小" # 大驼峰 # print(firstName, LastName) # 整形的表示形式,有四种 # 1.十进制,默认 # 2.二进制,0b或0B开头(数字0+字母b/B) # 3.八进制,0o或者00开头 # 4.十六进制,0x或oX开头 # 使用 type()函数查看变量的数据类型 # num1 = 34 # 十进制表示形式 # print(type(num1)) # 查看变量num1的数据类型, # num2 = 0b111 # 二进制表示形式 # print(type(num2)) # <class 'int'> # print(num2) # 7 # num3 = 0o10 # 八进制表示形式 # print(type(num3)) # <class 'int'> # print(num3) # 8 # num4 = 0xab # 十六进制表示形式 # print(type(num4)) # <class 'int'> # print(num4) # 171 """ # num1 = 64 # 把64赋值给num1 # num2 = bin(num1) # 64的二进制 # print(num2) # 输出64的二进制 # num3 = oct(num1) # num1的八进制 # print(num3) # 输出64的八进制 # num4 = hex(num1) # 64的十六进制 # print(num4) # 输出64的十六进制 # num5 = int('0b1000000', 2) # 把64的二进制换成十进制赋值给数字五 # print(num5) # 输出num5 # num6 = int('0o100', 8) # 把64的八进制换成十进制赋值给数字六 # print(num6) # 输出num6 # num7 = int('0x40', 16) # print(num7) # num8 = int('0b1101', 2) # print(num8) # num9 = int('0o567', 8) # print(num9) # num10 = int('0xabcd', 16) # print(num10) """ # num1 = 100 # num2 = bin(num1) # print(num2) # print(type(num2)) # num3 = int(num2, 2) # print(num3) # print(type(num3)) # num4 = oct(num3) # print(num4) # print(type(num4)) # 查看它的数据类型 # num5 = hex(100) # print(type(num5)) # num6 = int(0b11011) # print(num6) # 浮点数,小数,实数,float() # 表示形式,一般用十进制:1.直接写:314.152.科学计数,e/E:3.1415e2-->3.14*10*10 # 1.有一个十进制数64,写代码 # 2.分别转换成二进制八进制十六进制,形式的字符串并输出其结果 # 3.查看变量的数据类型 # 4.然后分别转回十进制数并输出其结果 # num1 = 314.15 # num2 = 3.14e2 # num3 = 56.78e-1 # 56.78*0.1 负数就往左边移动几位 # print(num1, num2, num3) # num4 = 123e-2 # 123*0.01 # print(num1, num2, num3, num4) # num5 = float(1234) # num6 = float("78.9") # print(num1, num2, num3, num4, num5, num6) # print(type(num1)) """ # 1.有一个十进制整数64,写代码, a = 64 # 2.分别转换为二进制、八进制、十六进制 形式的字符串并输出其结果。 b = bin(a) print(b) c = oct(a) print(c) d = hex(a) print(d) # 3.查看每个变量的数据类型, print(type(a)) print(type(b)) print(type(c)) print(type(d)) # 4.然后再分别转回十进制数并输出其结果。 b1 = int(b, 2) print(b1) c1 = int(c, 8) print(c1) d1 = int(d, 16) print(d1) """ # # 有一个二进制数0b1101, # b1 = 0b1101 # # 八进制数0o567, # o1 = 0o567 # # 十六进制数0xabcd, # h1 = 0xabcd # # 写代码把他们分别转换为十进制数并输出其结果。 # b2 = int(b1) # o2 = int(o1) # h2 = int(h1) # print(b2, o2, h2) # 数值型,复数,complex,complex(),real,imag # a = 3 + 2j # 变量a是复数,3实部,2j虚部,实部虚部都是浮点型 # print(type(a)) # print(a.real) # 获取复数的实部 # print(a.imagj) # 获取复数的虚部 # # complex 复数 # b = complex(4, 5) # print(b) # c = complex(7) # print(c) # d = complex(0, 2) # print(d) # 布尔类型,bool() # a = True # b = False # print(a) # print(b) # c = 0 # 整数0 # d = 0.0 # 浮点数0.0 # e = None # 空 # f = "" # 空字符串 # g = {} # 空字典 # h = [] # 空列表 # i = () # 空元组 # print(bool(c)) # 把一个数据转为布尔类型 # print(bool(d)) # print(bool(e)) # print(bool(f)) # print(bool(g)) # print(bool(h)) # print(bool(i)) # j = 1 # print(bool(j)) # k = 2.0 # print(bool(k)) # ll = "abc" # print(bool(ll)) # m = {"name": "zhangsan"} # print(bool(m)) # n = (1, 2, "a") # print(bool(n)) # o = (1, 2, 3) # print(bool(o)) # 算术运算符,+加,-减,*乘,/除,%余,**x的y次幂,//整除 # a = 3 # b = 5 # print(a + b) # 加 # print(a - b) # 减 # print(a * b) # 乘 # print(a / b) # 除 # print(a // b) # 整除 # print(a % b) # 取余,模 # print(a ** b) # 次幂 # a = True + 2 # print(a) # b = False - 1 # print(b) # 用算术运算符,计算两个数30,14,和。差。乘,除整除。模,次幂 # 布尔值,那些数据本身就是假的?那些数据本身就是真的?举例说明 # a = 30 # b = 14 # print(a + b) # print(a - b) # print(a * b) # print(a / b) # print(a // b) # print(a % b) # print(a ** b) # bool() # print(bool(0)) # print(bool(0.0)) # print(bool(None)) # print(bool("")) # print(bool({})) # print(bool([])) # print(bool()) # print(bool(1)) # print(bool(1.2)) # print(bool("123")) # print(bool({"age": 18})) # print(bool([1, "a"])) # print(bool((1, "a"))) # 浮点数,float,float() # 计算方式:十进直接写,十进制制科学计数法e/E # a = 123456.0 # b = 1.23456e5 # c = 123456000e-3 # print(a, b, c) # a1 = "567.89" # b1 = 89 # a2 = float(a1) # b2 = float(b1) # print(a2, b2) # 运算符,布尔值会被当成0或者1参与运算 # a = True + 5 # True会被当成1 # b = False + 7 # False被当成0 # print(a, 6) # 混合类型算数运算 # a = 10 # b = 3 + 2j # c = 2.5 # result1 = a + b # result2 = a - b # result3 = a * c # print(result1, result2, result3) # +,*作用于字符串 # print("=" * 30) # word1 = "Hello" # word2 = "word" # result4 = word1 + word2 # result5 = word1 * 5 # print(result4) # print(result5) # print("=" * 30) """ 赋值运算符: 1。=,将等号右边的数值赋给左边 2. =,复合赋值运算符:+= -= *= /= //= %= **= """ # a = 10 # b = 4 # a += b # print(a) # a:14 # a -= b # print(a) # a:10 # a *= b # print(a) # a:40 # a /= b # print(a) # a:10.0 # a //= b # print(a) # a:2.0 # b %= a # print(a) # b:0.0 # a **= b # print(a) # a:1.0 """ 比较运算符,结果是布尔值True或False == 等于 != 不等于 < 小于 > 大于 <= 小于等于 >= 大于等于 """ # a = 10 # b = 20 # print(a == b) # False # print(a != b) # True # print(a < b) # True # print(a <= b) # True # print(a > b) # False # print(a >= b) # False # c = a < b # 运算符优先级,比较运算符级别要高于赋值运算符 # print(c) # True # 逻辑运算符,not and or # x and y 逻辑与,短路,当x的值为false时,表达式的结果为false,不计算y的值(左右两个表达式或对象都为真时结果才为真 # 当x的值不为false时,表达式结果为y. # x = 0 # y = 5 # a = x and y # print(a) # 当x和y的条件都成立时,表达式才成立 # print(a) # a:0 # print(bool(a)) # false # m = 3 # n = 6 # b = m and n # print(b) # b:6 # print(bool(b)) # True """ 三好学生,两门成绩只要有一门大于等于一百分即可; 升班,两门成绩都大于等于60 """ # name = "张三" # core_1 = 120 # core_2 = 90 # result_1 = core_1 or core_2 # 两门分数三好学生的评定结果 # print(result_1 # name = input("请输入学生姓名") # input(),标准输入函数 # core_1 = float(input("请输入语文成绩")) # float()将input()接收到的字符串转为浮点数 # core_2 = float(input("请输入数学成绩")) # if core_1 >= 100 or core_2 >= 100: # print(name, "是三好学生") # else: # print(name, "不是三好学生") # if core_1 >= 60 and core_2 >= 60: # print(name, "能升班") # else: # print(name, "不能升班") # 运算符的优先级别 # 1.算术运算符 # 2.比较运算符 # 3.赋值运算符 # 4.逻辑运算符 # a = 20 # b = 10 # c = 15 # d = 5 # e = 0 # e = (a + b) * c / d # print(e) # # x = 10 # y = 20 # m = 3.0 # n = 8.2 # b = x + y > y * - 1 and m < n % 3 # print(b) # False # b1 = (x + y) > (x - y * (-1)) and m < (n % 3) # b2 = ((x + y) > (x - y * (-1))) and ((n % 3) > m) # print(b1) # True # print(b2) # False # input()函数,接受用户输入的数据,进行运算 # num_01 = int(input("请输入一个数字:")) # num_02 = int(input("请输入另一个数字:")) # sum = num_01 + num_02 # print("sum = ", sum) # print(type(num_01), type(num_02), type(sum)) # 题目要求:从键盘接受一个数字,判断奇偶,并把该数在显示出来。 # num_01 = int(input("请输入一个数字")) # if num_01 % 2: # print(num_01, "是奇数") # else: # print(num_01, "是偶数") # 身份运算符 判断两个对象是不是同一个对象,结果为布尔值 # is # is not # id()函数,查看对象的内存地址 # a = 10 # b = a # print(a is b) # true # print(a is not b) # False # print(id(a)) # print(id(b)) # c = 10.0 # print(a is c) # print(id(c)) # print(a == c) # 编写一个程序,用于判断来的某种物种能否进网吧,进网吧条件:人类,年龄大于等于18岁。 # name = "*" # core_1 = (input("请输入物种名称:")) # age = int(input("请输入物种年龄:")) # if core_1 == name and age >= 18: # print(name, "是人类可以进") # elif core_1 != name: # print(name, "不能进") # elif age <= 18: # print(name, "年龄不够不能进") # 变量a值为10,变量b的值为20,编程实现,判断a, b是否是同一个对象? # 2.字符串string = “I love python”, 另两个字符串”yy”, ”py”,判断这两个字符串是否包含在string中? # is # is not # id # a = 10 # b = a # print(a is b) # print(a is not b) # print(id(a)) # print(id(b)) # b = 20 # c = b # print(b is c) # print(id(c)) # print(a == c) # status = input("输入您的身份") # age = input("请输入您的年龄") # if status == "people" and age >= 18: # print("是人类,年龄大于十八岁,可以进入网吧") # else: # print("不能进入网吧") # a = 10 # b = 20 # print(a is b) # false # print(a is not b) # True # string1 = "I love python " # a = "yy" # b = "py" # print(a in string1) # False # print(b in string1) # True # a = 0 # b = 10 # if (a or b) and b: # print("结果为true") # else: # print("结果为false") # a = 2 # b = 2 # a = b # print(type(a)) # a = 10 # b = bin(a) # print(a) # 编写一个程序,用于实现两个数的交换。 # a = 10 # b = 20 # r = a # b = a # a = r # print(a, b) # 学习小组pk,一组包含5名同学,共两组,分别计算两组同学的笔试平均分,(具体考试分数自定义),看哪组成绩更优异。 # group_1 = (input("请输入第几小组")) # num_1 = (int(input("第一名同学成绩"))) # num_2 = (int(input("第二名同学成绩"))) # num_3 = (int(input("第三名同学成绩"))) # num_4 = (int(input("第四名同学成绩"))) # num_5 = (int(input("第五名同学成绩"))) # sum_1 = int(num_1 + num_2 + num_3 + num_4 + num_5) / 5 # print(num_1) # group_2 = (input("请输入第几小组:")) # num_6 = (int(input("第一名同学成绩"))) # num_7 = (int(input("第二名同学成绩"))) # num_8 = (int(input("第三名同学成绩"))) # num_9 = (int(input("第四名同学成绩"))) # num_10 = (int(input("第五名同学成绩"))) # sum_2 = int(num_6 + num_7 + num_8 + num_9 + num_10) / 5 # print(num_2) # if sum_1 == sum_2: # print(group_1, "和", group_2, "成绩相等") # else: # if sum_1 > sum_2: # print(group_1, "成绩优异") # else: # print(group_2, "成绩优异") # num_01 = int(input("请输入一个数字:")) # if num_01 > 0: # print(num_01, "是正数") # elif num_01 < 0: # print(num_01, "是负数") # elif num_01 == 0: # print(num_01, "为0") # else: # print("输入错误,请重新输入") """ 判断用户输入的数能否被2和三整除 """ # num_01 = int(input("请输入一个整数")) # if num_01 % 2 == 0: # print(num_01, "能够被2整除") # if num_01 % 3 == 0: # print(num_01,"能够被3整除") # else: # print(num_01, "不能够被3整除") # else: # print(num_01, "不能被2整除") # if num_01 % 3 == 0: # print(num_01, "能被3整除") # else: # print(num_01, "不能被3整除") # num_01 = int(input("请输入一个整数")) # if num_01 % 2 == 0: # if num_01 % 3 == 0: # print(num_01, "既能被2整除又能被3整除") # else: # print(num_01, "只能被2整除不能被3整除") # else: # if num_01 % 3 == 0: # print(num_01, "不能被2整除但是能被3整除") # else: # print(num_01, "既不能被2整除,也不能被3整除") # num_01 = int(input("请输入一个整数")) # if num_01 % 2 == 0: # print("这个数可以被2整除") # if num_01 % 3 == 0: # print(num_01, "既能被2整除又能被3整除") # print(num_01, "只能被2整除不能被3整除") # elif num_01 % 3 == 0: # print(num_01, "不能被2整除但是能被3整除") # else: # print(num_01, "既不能被2整除,也不能被3整除") # 1.编写一个程序,判断用户输入的数是正数还是负数。 # num_01 = float(input("请输入一个整数")) # if num_01 > 0: # print(num_01, "是正数") # elif num_01 == 0: # print(num_01, "既不是正数也不是负数") # else: # print(num_01, "是负数") ''' 运算符的优先级别 1.可以使用()改变优先级别 2.**,+(正),负 3.*,/,% 4.+ - (加减) 5. > >= < <= == != 6.is is not (身份运算符) 7.in not in (成员运算符) 8.not (逻辑运算符) 9.and (逻辑运算符) 10.or (逻辑运算符) ''' # a = 10 # b = 20 # c = a * (b + a) # print(c) # c=300 # a += b # print("a=", a) # a=30 # b += a # print("b=", b) # b=50 # c = a and b # print("c=", c) # c=50 # d = a or b # print("d=", d) # d=30 # e = not a # print("e=", e) # e=False # f = 0 and b # print("f=", f) # f = 0 # g = 0 or b # print("g=", g) # g = 50 # string_1 = "I love puthon" # string_2 = "py" # string_3 = "pp" # print(string_2 in string_1) # print(string_3 in string_1) # print(string_2 not in string_1) # print(string_3 not in string_1) # string_22 = "py" # print(string_2 is string_22) # print(string_2 == string_22) # aa = 0 # cc = aa # dd = 0.0 # print(aa is cc) # print(aa is not cc) # print(dd is not cc) # print(dd is cc) # print(dd == cc) # # if 条件判断,根据考试成绩定等级a,b,c,d,不及格 # score = int(input("请输入成绩")) # if score >= 90: # print("A") # elif score >= 80: # print("B") # elif score >= 70: # print("C") # elif score <= 60: # print("D") # 循环语句,while # while 条件表达式 # 为真实执行的代码块 # 求0-10之间的整数和 # i = 0 # sum_1 = 0 # while i <= 10: # sum_1 += i # i += 1 # print("0-10之间的整数和为:", sum_1) # 55 # 求1-100的偶数和 # i = 1 # sum_02 = 0 # while i <= 100: # if i % 2 == 0: # sum_02 += i # i += 1 # print("1-100的偶数和为:", sum_02) # 猜数字 # guess = -1 # number_01 = 9 # while guess != number_01: # guess = int(input("请输入一个整数:")) # if guess > number_01: # print("输入的大了,请重新输入") # elif guess < number_01: # print("输入的小了,请重新输入") # elif guess == number_01: # print("恭喜你,猜对了!") # i = 1 # num_02 = 0 # while i <= 100: # if i % 2 == 0: # num_02 += i # i += 1 # # print("1-100的偶数和为:", num_02) # a = int(input("请输入一个数")) # if a>=100: # print("请重新输入") # elif 90<=a: # print("优秀") # elif 80 <=a: # print("良好") # elif 70<=a: # print("还可以") # elif 60 <=a: # print("及格") # elif a<60: # print("不及格") # a = int(input("输入成绩")) # if a > 100: # print("重新输入") # a = input("输入") # if a > 90: # print("优秀") # elif a > 80: # print("良好") # elif a > 70: # print("可以") # elif a > 60: # print("及格") # else: # print("不及格")