Build a Medical Data Validator - Step 13

Tell us what’s happening:

I have tried wrapping this in str in every way that I can think of, to run the test, and it IS saying the expected invalid format: expected a list or tuple line, but for some reason, again I can’t get it to clear even though I’m pretty sure I have it in there correctly.

medical_records = (type(str)[
{
‘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,

Your code so far

# User Editable Region
medical_records = (type(str) [
    {
        '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',
    }
])
# User Editable Region

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

validate(medical_records)

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15

Challenge Information:

Build a Medical Data Validator - Step 13

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-medical-data-validator/6846a82852dae0bba941a9a1.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @danielsmom1250s,

Yes; you are getting the expected message, but it’s not because medical_records is now type string.

Try adding print(type(medical_records)) before your function call to test its type. Surprised?

To pass the tests, make it easy on yourself. Just comment out the medical_records array of objects and create a new medical_records variable assigned to an empty string. :slight_smile:

Happy coding

Hi @danielsmom1250s

Try doing it without using the type function.

Happy coding