运算符和编码

1.写一个判断3次输入语句
2.写一个登陆程序
3.两个程序结合
 
#判断3次输入语句
count=3
while count>0:
    count=count-1
print("您还有%s次机会"%(count))
#登录程序
1 username = input('please input your username:')
2 password = input("please input your password:")
3 if (username == 'sylar') and (password == 'alex'):
4     print("恭喜您登陆成功!")
5 else:
6     print("登录失败")
 
# 程序合并
count=3
while count>0:
    count=count-1
    username = input('please input your username:')
    password = input("please input your password:")
    if (username == 'sylar') and (password == 'alex'):
        print("恭喜您登陆成功!")
        break
else:
        print("登录失败")
    print("您还有%s次机会"%(count))
 
 
 
 
 
 
 
编程一定要注意 如果需要循环 一定要先用while 进行循环  在进行if 语句判断
大写字母A的ASCII码65  (十进制)
 
 
1 格式化输出
    %s    字符串
    %d   整数
    %f    浮点数
 
#格式化输出
 
name=input('请输入名字:')
age=int(input("请输入年龄:"))
job=input('请输入工作:')
hobby=input('请输入爱好:')

print('''------------ info of %s -----------
Name : %s
Age : %d
job : %s
Hobbie:%s
------------- end --------------'''%(name,name,age,job,hobby))
 
 
# %s 字符串 %d 整数 %f 浮点数 如果你的字符串中.用了%s或者%d这种形式. 那么后面的%, 认为是站位.如果需要用到% . 需要写%%
 
print('我是%s,加载到了2%%'%('小老板'))
2 运算符
    //    整除
    %    计算余数
    a+=b   =>    a=a+b
    and    两边都是真则真,有一个是假则假
    or    两边只要有一个是真就是真
    not    非真既假,非假既真
 
运算顺序 () => not => and => or . 同样的运算符从左往右算
#print(3>4 or 4<3 and 1==1)    # F
#print(1 < 2 and 3 < 4 or 1>2)    # T
#print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # T
#print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # F
 
# or 如果第一位是非零. 输出第一位. 如果是 零输出第二位
# and 如果第一位是零,输出第一位,如果第一位非零输出第二位
#print(1 and 2)    # 2
#print(0 and 2)    # 0
#print(1 and 3)    # 3
#print(2 and 3)    # 3
#print(2 or 0 or 3)    # 2
#print(1 or 3 or 4)    # 1
#print(3 and 5 and 0)    # 5 0
#print(0 or 0 or 5 or 3) # 5
 
补充while 
index = 0
while index < 5:
    if index == 3:
        break    # break的时候不会执行while后面的else
    print("旭哥")
    index = index + 1
else:    # 条件不成立. 执行的代码
    print("梁姐")
 
# in 可以帮我们判断xxx字符串是否出现在xxxxxxx字符串中
content = input("请输入你的评论:")
# 马化腾是特殊字符
if "马化腾" in content:
    print("非法的")
else:
    print("合法的")
    
# not in 没有出现xxx
 
 
3.编码
ASCII     由8bit组成1 个字节(byte)
GBK      有中文    由16bit组成2个字节(byte)
Unicode    万国码 占32位 由32bit组成4个字节(byte)
utf-8    可变长度的Unicode编码,  8的意思是最少由8个bit

猜你喜欢

转载自www.cnblogs.com/chyxlj/p/9366064.html