【第一模块】Python随堂笔记-2

10. 元组(有序的,固定的,元素不可改变)

创建元组:
ages  =   ( 11 22 33 44 55 )
ages = tuple((1122334455))
11. 字典(无序的,区分键和值,即key和value)
person = {"name""mr.wu"'age'18}
或者
person = dict({"name""mr.wu"'age'18})
注意:字典中元素类型可不一致

常用操作:

  • 索引    
  • 新增
  • 删除
  • 键、值、键值对
  • 循环
  • 长度
12.数据运算(标*为常用的)
算数运算*
比较运算*
赋值运算*
逻辑运算*
成员运算
位运算
身份运算
运算符优先级:

13. 几个小程序
1)while小程序:
age_of_oldboy = 56
count = 0
while count < 3:
    guess_age = int(input("guess_age:"))
    if guess_age == age_of_oldboy:
        print("yes, you got it!")
        break
    elif guess_age > age_of_oldboy:
        print("think smaller")
    else:
        print("think bigger!")
    count += 1
#if count ==3:
else:
    print("you have tried too many times!")

2)guess任性玩
__author__ = 'wangliping1'
age_of_oldboy = 56
count = 0
while count < 3:
    guess_age = int(input("guess_age:"))
    if guess_age == age_of_oldboy:
        print("yes, you got it!")
        break
    elif guess_age > age_of_oldboy:
        print("think smaller")
    else:
        print("think bigger!")
    count += 1
    if count == 3:   #猜测到3次时,询问用户是否继续猜
        continue_flag = input("Do you want to continue guessing? Y/N")
        if continue_flag == "Y":
            count = 0    #继续猜,计数清零
        if continue_flag == "N":
            break       #不继续猜,结束循环


3)password小程序
username = input("username:")
#password = getpass.getpass("password:")
password = input("password:")
_username = "liping"
_password = "abc123"
if username == _username and password == _password:
    print("welcome user {name} login...".format(name = username))
else:
    print("invalid username or password!")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值