def people(height,weight,*infos):
"""介紹一個人的個人資訊"""
promote="輸入你的名字:"
name=input(promote)
while name=='zhang':
print(name+"的身高是:"+str(height)+",體重是:"+str(weight))
break
for info in infos:
print("他最喜歡的食物是:"+info)
from module_name import people
people(175,'85KG',"chocolate")
我想可不可以輸入一個人的名字就能調出他的資訊,可以這個條件怎么設定啊,比如我還有另一個人的名字,輸入他的名字要怎么列印他的資訊呢?大佬們求救
uj5u.com熱心網友回復:
user_dict = {"zhang":[175,'85KG',"chocolate"],"li":[180,'70KG',"apple"] }
def people():
"""介紹一個人的個人資訊"""
promote="輸入你的名字:"
name=input(promote)
# 判斷name存不存在user_dict字典里 如果不存在會為None
userinfo = user_dict.get(name)
if userinfo is None:
print("查無此人")
else:
print(name+"的身高是:"+str(userinfo[0])+",體重是:"+userinfo[1])
print("他最喜歡的食物是:"+str(userinfo[2]))
people()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/121632.html
