老男孩Day3

内容目录

一、上周五内容回顾

二、作业

三、数据类型

1、int

2、bool

3、str

4、数据类型的转换

一、上周五内容回顾
格式化输出
%s %d
%%
编码:
ascii 只能显示英文,特殊字符,数字。
万国码:unicode 最开始16位,中文不够32位 4个字节。
占用资源多。
升级:utf-8 utf-16 utf-32
utf-8:最少用一个字节,8位表示一个英文。
欧洲16位,两个字节。
亚洲 24位,三个字节。
gbk:中国国产,只能用于中文和ascii码中的文字。

二、作业

用户登录,三次机会。

#账号密码同时检验
count = 0
while count < 3:
    username = int(input('请输入您的账号:'))
    password = int(input('请输入您的密码:'))
    if username == 1 and password == 2:
        print('登录成功')
        break
    else:
        print('登录失败,请重新登录')
    count += 1

#账号密码同时检验,用格式化输出
i = 3
username = '杨鑫'
password = 'yangxin'
while i > 0:
    i -= 1
    name = input('请输入您的账号:')
    passwd = input('请输入您的密码:')
    if name == username and passwd == password:
        print('登录成功')
        print('''
账号:%s
密码:%s
        '''%(username,password))
        break
    if name != username or passwd != password:
        if i != 0:
            print('您的账号密码错误,您还有%s次机会'%(i))
        else:
            print('您的账号已冻结')

##账号密码分开检验,用格式化输出
i = 3
username = '杨鑫'
password = 'yangxin'
while i > 0:
    i -= 1
    name = input('请输入您的账号:')
    if name == username:
        passwd = input('请输入您的密码:')
        if passwd == password:
            print('登录成功')
            print('''
            账号:%s
            密码:%s
            '''%(username,password))
            break
        else:
            if i == 0:
                print('登录失败')
                answer = input('再试试? Y or N')
                if answer == 'Y':
                    i = 3
            print('密码错误,您还有'+str(i)+'次机会' )
    else:
        if i == 0:
            print('登录失败')
            answer = input('再试试? Y or N')
            if answer == 'Y':
                i = 3
        print('账号错误,您还有'+str(i)+'次机会' )
else:
    print('要不要脸')

三、什么数据类型
int 1,2,3用于计算。
bool:True,False,用户判断。
str:存储少量数据,进行操作
'fjdsal' '二哥','`13243','fdshklj'
'战三,李四,王二麻子。。。。'
list:储存大量的数据。
[1,2,3,'泰哥','12353234',[1,2,3]]
元祖:只读。
(1,2,3,'第三方',)
dict:字典{'name':'云姐','age':16}
字典{'云姐':[],'二哥':[200,200,200,。。。。。。]}
集合:{1,2,34,'asdf'}

1、int

i = 100
print(i.bit_length())
'''
                  bit_length
1     0000 0001       1
2     0000 0010       2
3     0000 0011       2
'''


2、bool

#bool  True False
   


3、str

#字符串的索引与切片
s = 'ABCDEFG'
#索引
#A
s1 = s[0]
print(s1)
#C
s2 = s[2]
print(s2)
#G
s3 = s[-1]
print(s3)
#F
s4 = s[-2]
print(s4)

#切片:顾头不顾尾
#ABCD
s5 = s[0:4]
print(s5)
#ABCDEF
s6 = s[0:-1]
print(s6)
#ABCDEFG
s7 = s[0:]   # or s7 = s[:]
print(s7)
#ACE
s8 = s[0:5:2]     # s[首:尾:步长]
print(s8)

#DCBA
s9 = s[3::-1]
print(s9)
#DC
s10 = s[3::-2]
print(s10)
#GFEDCBA
s11 = s[-1::-1]    # or    s11 = s[::-1]
print(s11)

4、数据类型的转换

#int ----> str
i = 1
s = str(i)
#str ---> int
s = '123'
i = int(s)

#int ----->bool  只要是0 ----》False  非0就是True
i = 3
b = bool(i)
print(b)
#bool----> int
#True   1
#False  0
'''
ps:
while True:
    pass
while 1: 效率高
    pass
'''

#str --->bool

#s = "" -----> False
#非空字符串都是True
#s = "0" -----> True

# s
# if s:
#     print('你输入的为空,请重新输入')
# else:
#     pass

猜你喜欢

转载自www.cnblogs.com/Alex216/p/10570631.html