2020Python练习一

2020Python练习一

@2020.3.4

Python语法入门-变量和基本数据类型-练习一

 

习题

#1、病毒程序需要定期将监控到的数据写入日志文件,请记录下日志文件路径C:acadhsvc.dll.system32,方便后期处理

>>> 
>>> logePath ="C:/a/b/c/adhsvc.dll.system32"
>>> print(logePath)
C:/a/b/c/adhsvc.dll.system32
>>> 

#2、病毒程序在上传文件时,发送的报头数据里需要包含文件信息:文件名a.txt、大小360,请记录下文件信息

>>> fileMessage={"文件名":"a.txt","大小":360}
>>> print(fileMessage)
{"文件名": "a.txt", "大小": 360}

#3、程序运行过程中有一段错误日志需要记录下来,错误日志为"上传文件失败" 

>>> 
>>> wrongLoge="上传文件失败"
>>> print(wrongLoge)
上传文件失败
>>>

#4、假设我收到一条信息要记录,信息为中病毒客户端的信息"[2020-02-18-17:00:48] 癞蛤蟆病毒感染者-> 80.82.70.187:33649 正在上传数据"

>>> messsge="[2020-02-18-17:00:48] 癞蛤蟆病毒感染者-> 80.82.70.187:33649 正在上传数据"
>>> print(messsge)
[2020-02-18-17:00:48] 癞蛤蟆病毒感染者-> 80.82.70.187:33649 正在上传数据

#5、把服务端ip地址存放下来,ip地址为10.0.10.11

>>> ip="10.0.10.11"
>>> print(ip)
10.0.10.11

#6、病毒程序需要每隔3秒才运行一次,请记录下这个时间间隔 

>>> 
>>> time=3
>>> print(time)
3
>>> 


# 二:嵌套取值操作


#1、针对列表
students_info=[["egon",18,["play",]],["alex",18,["play","sleep"]]]
请取出第一个学生的第一个爱好

  

>>> students_info=[["egon",18,["play",]],["alex",18,["play","sleep"]]]
>>> print(students_info[0][2][0]) #[0]才是列表中的第一个数据
play

#2、针对字典
字典嵌套字典:
info={
    "name":"egon",
    "hobbies":["play","sleep"],
    "company_info":{
        "name":"Oldboy",
        "type":"education",
        "emp_num":40,
    }
}
请取出取公司名 

>>> 
>>> info={
    "name":"egon",
    "hobbies":["play","sleep"],
    "company_info":{
        "name":"Oldboy",
        "type":"education",
        "emp_num":40,
    }
}
>>> print(info["company_info"]["name"])#取出嵌套字典中的公司名
Oldboy
>>> 


#3、针对下述类型
列表嵌套字典:
students=[
    {"name":"alex","age":38,"hobbies":["play","sleep"]},
    {"name":"egon","age":18,"hobbies":["read","sleep"]},
    {"name":"wupeiqi","age":58,"hobbies":["music","read","sleep"]},
]
取第二个学生的第二个爱好 

>>> 
>>> 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])
sleep
>>>