Home > other >  Novice himself wrote a program, to achieve a function, but don't know how to do
Novice himself wrote a program, to achieve a function, but don't know how to do

Time:10-09

Def people (height, weight, * infos) :
"" "introduction to a person's personal information ", "
Promote="input your name:"
Name=input (promote)
While name=='zhang' :
Print (name + "height is:" + STR (height) + ", weight is: "+ STR (weight))
Break
For the info in infos:
Print (" he favorite food is: "+ info)



The from module_name import people
People (175, '85 kg, "chocolate")


Can I want to enter the name of a person can bring up his information, how can this condition Settings, such as I have another name, enter his name how to print his information? Bosses for

CodePudding user response:

 user_dict={" zhang ": [175, '85 kg," chocolate "], "li" : [180,' 70 kg, "apple"]} 

Def people () :
"" "introduction to a person's personal information ", "
Promote="input your name:"
Name=input (promote)
# to judge the name not exist user_dict dictionary if there is no will to None
The userinfo=user_dict. Get (name)
If the userinfo is None:
Print (" no such person ")
The else:
Print (name + "height is:" + STR (the userinfo [0]) + ", weight is: "+ the userinfo [1])
Print (" he favorite food is: "+ STR (the userinfo [2]))

People ()
  • Related