码迷,mamicode.com
首页 > 其他好文 > 详细

变量与基本数据类型

时间:2020-12-31 12:02:21      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:不同的   基本数据   操作   输入   read   auto   div   oid   数据类型   

嵌套取值操作

1. 请取出第一个学生的第一个爱好

 

students_info = [[egon, 18, [play, ]], [alex, 18, [play, sleep]]]
print(students_info[0][2][0])

 

2. 针对字典,请取出取公司名

info = {
    name: egon,
    hobbies: [play, sleep],
    company_info: {
        name: Old boy,
        type: education,
        emp_num: 40,
    }
}
#  请取出取公司名:
print(info[company_info][name])

3. 针对下述类型,取第二个学生的第二个爱好

students = [
    {name: alex, age: 38, hobbies: [play, sleep]},
    {name: egon, age: 18, hobbies: [read, sleep]},
    {name: wupeiqi, age: 58, hobbies: [music, read, sleep]},
]

print(students[1][hobbies][1])

附加题

1. 输入账号密码完成验证,验证通过后输出"登录成功"

while True:
    account = input(your account:)
    password = input(your password)
    if account == Avery:
        if password == 369:
            print(登陆成功)
            exit()
        else:
            print(密码输入错误,请重新输入)
            continue
    else:
        print(账号输入错误,请重新输入)

2. 可以登录不同的用户

account_dic = {
    Avery: 369,
    Kaia: 123
}
while True:
    account = input(your account:)
    password = input(your password)
    if account in account_dic:
        if password == account_dic[account]:
            print(登陆成功)
            exit()
        else:
            print(密码输入错误,请重新输入)
            continue
    else:
        print(账号输入错误,请重新输入)

 

变量与基本数据类型

标签:不同的   基本数据   操作   输入   read   auto   div   oid   数据类型   

原文地址:https://www.cnblogs.com/avery-w/p/14192842.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!