[Python] Python Nested Dictionary Invalid Syntax error "Perhaps you need a comma" [closed]

Discussão em 'Python' iniciado por Stack, Março 28, 2025.

  1. Stack

    Stack Membro Participativo

    Code

    #Start

    #Room_Number = dict (CSC101=3004,CSC102=4501)
    #print (Room_Number)

    Course_Key = {
    'CSC101': {
    'Room': "3004",
    'Teacher': "Haynes",
    'Meeting': "8:00 a.m."
    }
    'CSC102': {
    'Room': "4501",
    'Teacher': 'Alvarado',
    'Meeting': "9:00 a.m."
    },
    }
    print (Course_Key)


    output:

    ERROR!
    Traceback (most recent call last):
    File "<main.py>", line 7
    'CSC101': {

    SyntaxError: invalid syntax. Perhaps you forgot a comma?


    So I'm very new to python, its giving me an error on line 7 at the { saying perhaps I need a comma. I've looked at several examples of this and I can't figure out what I'm doing wrong here. Any help would be appreciated.

    I'm just trying to create a nested dictionary and then print it for practice so I understand how it works at what to expect I got a normal dictionary to work just fine but the nested one is saying perhaps I'm missing a comma but I don't see any extra commas in the examples or text books I looked at and I feel like I'm missing something else.

    Continue reading...

Compartilhe esta Página