Build a Medical Data Validator - Step 9

Tell us what’s happening:

despite using {},still not able to print variable in f statemnt

Your code so far

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


# User Editable Region

    for index, dictionary in enumerate(data):
        if not isinstance(dictionary,dict):
            print(f" Invalid format: expected a dictionary at position {index}.")
            is_invalid=True

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Medical Data Validator - Step 9

You have an extra space at the beginning of your string

I think I see what’s going on with your f-string. A few common things can trip people up:

Make sure the string starts with f – without it, Python just treats it as a normal string and won’t evaluate anything inside {}.

removed

That should fix your f-string issues and make your messages actually show the variable values. :blush:

Please do not post LLM answers on the forum

1 Like

unfortunately nothing worked after that change,i appreciate it thou!,i keep getting this (You should print Invalid format: expected a dictionary at position <index>. (where <index> should be replaced by the current index) inside your if statement.),am sure the code is very pythonic and on my IDE it runs very well,am very confused is this a bug?

there isn’t a bug in the tests

consider, is your string supposed to start with a space?

If I fix the space, the test passes for me.

Please share your updated code.

Being pythonic or running on an IDE doesn’t really matter. It needs to follow the instructions and pass the tests.