def print_poetry():
print("床前明月光")
print("疑似地上霜")
print("举头望明月")
print("疑似地上霜")
return "李白"
author = print_poetry()
print("作者是{name}".format(name=author))
def health_check(name, height, weight, h, age="13"):
print(age)
print(height)
print("您的健康状况良好")
return "okk"
print(health_check(name="张三", height="123", weight="123", h="123"))
def health_check1(name, age, *, height, weight, h):
print("您的姓名是:{},年龄:{}".format(name, age))
print("您的身体状况良好")
return "ok"
print(health_check1("张三", 13, height=13, weight=14, h=5))
json1 = {"name": "张三", "age": 13, "address": "中国重庆市南岸区"}
health_check(json1.get("name"), json1.get("age"), 1123, 123)
"""
序列传参
"""
import random
def health_check1(name, age, height, weight, h):
print("您的姓名是:{},年龄:{}".format(name, age))
print("您的身体状况良好")
return "ok"
list1 = ["张三", 13, 170, 70, 4]
print(health_check1(*list1))
print("===============================")
"""
字典传参
"""
dict1 = {"name": "李四", "age": 13, "height": 180, "weight": 75, "h": 123}
print(health_check1(**dict1))
print("===============================")
"""
返回多个数据的方法
"""
def get_dict_info():
result = {
"employee": [
{"name": "张三", "age": 13, "address": "重庆"},
{"name": "李四", "age": 24, "address": "上海"}
],
"device": {
8873434: {"name": "超级游戏笔记本", "price": "12333$"},
9934834: {"name": "超级跑车", "price": "2000000$"}
},
"city": {},
"student": {}
}
return result
json = get_dict_info()
print(json.get("employee")[0].get("name"))
"""
个人练习 生活小助理
"""
import random
def random_num(number):
for a in range(0, number):
for i in range(0, 6):
print(random.randint(1, 33), end=" ")
print(random.randint(1, 16))
def query_phone_number(query_str):
phone_list = phone.split(",")
for p in phone_list:
if query_str in p:
print(p)
def query_weather(query_city):
city_list = citys.split("~")
dict1 = {}
for i in range(0, len(city_list)):
temp_city = city_list[i].split(",")
dict1[temp_city[0]] = {"city": temp_city[0], "date": temp_city[1], "a": temp_city[2], "b": temp_city[3],
"c": temp_city[4], "d": temp_city[5]}
query_city = dict1.get(query_city)
if query_city is not None:
print("{city}市{date}天气{a}最高温度{b}最低问题{c}风向{d}".format_map(query_city))
else:
print("未查询到天气情况")
phone = "匪警[110],火警[119],急救中心[120],道路交通事故报警[122],水上求救专用电话[12395],天气预报[12121],报时服务[12117],森林火警[12119],电力服务[95598],红十字会急救台[999],公安短信报警[12110],通用紧急求救[112],信产部IP/网站备案[010-66411166]"
citys = "北京,2019年1月12日,多云,8°C,-4°C,南风3级~上海,2019年1月12日,小雨,9°C,6°C,北风2级~广州,2019年1月12日,阵雨转多云,22°C,15°C,持续无风向微风"
print("欢迎访问生活小助手")
while True:
print("1-双色球随机选号")
print("2-号码百事通")
print("3-明日天气预报")
print("0-结束程序")
n = int(input("请输入功能编号:"))
if n == 1:
num = int(input("您要生成几注双色球号码:"))
random_num(num)
elif n == 2:
query = input("请输入您要查询的机构或者电话号码:")
query_phone_number(query_str=query)
elif n == 3:
city = input("请输入您要查询的城市:")
query_weather(query_city=city)
elif n == 0:
print("欢迎使用生活助手,再见!")
break
else:
print("输入错误,请重新输入")
print("=" * 50)