1,回顾昨天课程及作业
1 #1.使用while循环输入 1 2 3 4 5 6 8 9 10 2 3 ''' 4 count = 0 5 while count < 10: 6 count += 1 # count = count +1 7 if count == 7: 8 print(' ') 9 else: 10 print(count) 11 #第二方法 12 13 count = 0 14 while count < 10: 15 count += 1 # count = count +1 16 if count == 7: 17 continue 18 print(count) 19 20 ''' 21 #3、输出 1-100 内的所有奇数 22 #方法一: 23 # count = 1 24 # while count < 101: 25 # print(count) 26 # count += 2 27 #方法二: 28 # count = 1 29 # while count < 101: 30 # if count % 2 == 1: 31 # print(count) 32 # count += 1 33 34 #5、求1-2+3-4+5 ... 99的所有数的和 35 # sum = 0 36 # count = 1 37 # while count < 100: 38 # if count % 2 == 0: 39 # sum = sum - count 40 # else: 41 # sum = sum + count 42 # count += 1 43 # print(sum) 44 45 #6、用户登陆(三次机会重试) 46 #input 心中有账号,密码 while 47 48 i = 0 49 while i < 3: 50 username = input('请输入账号:') 51 password = int(input('请输入密码:')) 52 if username == '咸鱼哥' and password == 123: 53 print('登录成功') 54 else: 55 print('登录失败请重新登录') 56 i += 1
2,格式化输出
#格式化输出 # % s d # name = input('请输入姓名') # age = input('请输入年龄') # height = input('请输入身高') # msg = "我叫%s,今年%s 身高 %s" %(name,age,height) # print(msg) """ name = input('请输入姓名:') age = input('请输入年龄:') job = input('请输入工作:') hobbie = input('你的爱好:') msg = '''------------ info of %s ----------- Name : %s Age : %d job : %s Hobbie: %s ------------- end -----------------''' %(name,name,int(age),job,hobbie) print(msg) """ name = input('请输入姓名') age = input('请输入年龄') height = input('请输入身高') msg = "我叫%s,今年%s 身高 %s 学习进度为3%%s" %(name,age,height) print(msg)
3,while else循环语句
count = 0 while count <= 5 : count += 1 if count == 3:break print("Loop",count) else: print("循环正常执行完啦") print("-----out of while loop ------")
4,初始编码
1 新 2 开 3 一 4 家 5 看 6 看 7 A B C 8 01000010 01000011 9 电报,电脑的传输,存储都是01010101 10 11 最早的'密码本' ascii 涵盖了英文字母大小写,特殊字符,数字。 12 ascii 只能表示256种可能,太少, 13 创办了万国码 unicode 14 16表示一个字符不行,32位表示一个字符。 15 A 01000001010000010100000101000001 16 B 01000010010000100100001001000010 17 我 01000010010000100100001001000010 18 Unicode 升级 utf-8 utf-16 utf-32 19 8位 = 1字节bytes 20 utf-8 一个字符最少用8位去表示,英文用8位 一个字节 21 欧洲文字用16位去表示 两个字节 22 中文用24 位去表示 三个字节 23 utf-16 一个字符最少用16位去表示 24 25 gbk 中国人自己发明的,一个中文用两个字节 16位去表示。 26 27 1bit 8bit = 1bytes 28 1byte 1024byte = 1KB 29 1KB 1024kb = 1MB 30 1MB 1024MB = 1GB 31 1GB 1024GB = 1TB
5,逻辑运算
1 #and or not 2 #优先级,()> not > and > or 3 # print(2 > 1 and 1 < 4) 4 # print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2) 5 # T or T or F 6 #T or F 7 # print(3>4 or 4<3 and 1==1) # F 8 # print(1 < 2 and 3 < 4 or 1>2) # T 9 # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T 10 # print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F 11 # print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F 12 # print(not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # F 13 14 #ps int ----> bool 非零转换成bool True 0 转换成bool 是False 15 # print(bool(2)) 16 # print(bool(-2)) 17 # print(bool(0)) 18 # #bool --->int 19 # print(int(True)) # 1 20 # print(int(False)) # 0 21 22 23 '''x or y x True,则返回x''' 24 # print(1 or 2) # 1 25 # print(3 or 2) # 3 26 # print(0 or 2) # 2 27 # print(0 or 100) # 100 28 29 30 # print(2 or 100 or 3 or 4) # 2 31 32 # print(0 or 4 and 3 or 2) 33 '''x and y x True,则返回y''' 34 # print(1 and 2) 35 # print(0 and 2) 36 print(2 or 1 < 3) 37 print(3 > 1 or 2 and 2)