告诉我们发生了什么:
我在完成这一步时遇到了困难。我尝试了将 medical_records 变量转换为字符串并调用 validate 函数,但测试一直提示“你应该将你的 medical_records 列表转换成字串”。希望获得关于这一步的具体写法或排错指导。
I am having trouble with this step. I tried converting the medical_records variable to a string and calling the validate function, but the test keeps prompting “You should convert your medical_records list into a string.” I would appreciate some guidance on the exact syntax or troubleshooting for this step.
medical_str = str(medical_records)
validate(medical_str)
你目前的代码
# User Editable Region
medical_records = [
{
'patient_id': 'P1001',
'age': 34,
'gender': 'Female',
'diagnosis': 'Hypertension',
'medications': ['Lisinopril'],
'last_visit_id': 'V2301',
},
{
'patient_id': 'p1002',
'age': 47,
'gender': 'male',
'diagnosis': 'Type 2 Diabetes',
'medications': ['Metformin', 'Insulin'],
'last_visit_id': 'v2302',
},
{
'patient_id': 'P1003',
'age': 29,
'gender': 'female',
'diagnosis': 'Asthma',
'medications': ['Albuterol'],
'last_visit_id': 'v2303',
},
{
'patient_id': 'p1004',
'age': 56,
'gender': 'Male',
'diagnosis': 'Chronic Back Pain',
'medications': ['Ibuprofen', 'Physical Therapy'],
'last_visit_id': 'V2304',
}
]
def validate(data):
is_sequence = isinstance(data, (list, tuple))
if not is_sequence:
print('Invalid format: expected a list or tuple.')
return False
is_invalid = False
for index, dictionary in enumerate(data):
if not isinstance(dictionary, dict):
print(f'Invalid format: expected a dictionary at position {index}.')
is_invalid = True
if is_invalid:
return False
print('Valid format.')
return True
medical_str = str(medical_records)
validate(medical_str)
# User Editable Region
你的浏览器信息:
用户代理是:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
挑战信息:
创建一个医疗数据验证器 - 步骤 13