【发布时间】:2018-09-05 17:44:44
【问题描述】:
我学习了列表、元组和字典的基本概念以及条件语句。并开始编写简单的代码来接受用户输入并根据输入的输入创建字典并打印字典内容。
代码写好了——
patientCount = 0
noOfPatients = input("\nHow many Patient's to Admit: ")
while (patientCount < int(noOfPatients)):
print("\nEnter the Details of the Patient {} :".format(patientCount+1))
patientFirstName = input("{:>30}".format("Enter the FIRST NAME: "))
patientLastName = input("{:>30}".format("Enter the LAST NAME: "))
patientMRN = input("{:>30}".format("Enter the MRN: "))
patientGender = input("{:>30}".format("Enter the GENDER (M/F/O): "))
patientBirthYear = input("{:>30}".format("Enter the BIRTH YEAR: "))
patientAge = input("{:>30}".format("Enter the AGE: "))
patientCount +=1
控制台输出:
How many Patient's to Admit ?: 2
Enter the Details of the Patient 1 :
Enter the FIRST NAME: David
Enter the LAST NAME: John
Enter the MRN: 878783
Enter the GENDER (M/F/O): M
Enter the BIRTH YEAR (YYYY): 1901
Patient AGE is: 117 Years
-------------------------
Enter the Details of the Patient 2 :
Enter the FIRST NAME: Sam
Enter the LAST NAME: Tommy
Enter the MRN: 76487236
Enter the GENDER (M/F/O): F
Enter the BIRTH YEAR (YYYY): 1990
Patient AGE is: 28 Years
创建了一个初始的空字典 -
patientDatabase = {}
我想从上面输入的代码中创建嵌套字典,如下所示 -
patientDatabase = {
Patient 1:{'First Name':'David', 'Last Name': 'John',
'MRN': 878783, 'Gender': 'M', BirthYear': 1901, 'Age': 117},
Patient2:{'First Name':'Sam', 'Last Name': 'Tommy',
'MRN': 76487236, 'Gender': 'F', BirthYear': 1990, 'Age': 28} }
当打印上面的字典时,我正在寻找的输出如下 -
Patient 1 Details:
--------------------
FIRST NAME: David
LAST NAME: John
MRN: 878783
GENDER: M
BIRTH YEAR: 1901
AGE: 117 Years
Patient 2 Details:
--------------------
FIRST NAME: Sam
LAST NAME: Tommy
MRN: 76487236
GENDER: F
BIRTH YEAR: 1990
AGE: 28 Years
有人可以帮我吗?
【问题讨论】:
标签: python-3.x list dictionary