Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Learning Python, using an online compiler to check for something, it throws an exception when assigning a list

I am using three lists to format something. However, when assigning values to the lists, I get this exception:

  File "main.py", line 1
    first-operand-list = ['', '  ', '3801', '    ', '  ', '123'];
    ^
SyntaxError: cannot assign to operator

Could anyone explain why? Here is the code:

first-operand-list = ['', '  ', '3801', '    ', '  ', '123'];
second-operator-list = ['', '-    ', '2', '    ', '+  ', '49'];
line-list = ['------', '    ', '-----', '    '];

def to_result():
    row_one = "".join(first_operand_list);
    row_two = "".join(second_operand_list);
    row_three = "".join(line_list);
    math = row_one + '\n' + row_two + '\n' + row_three;
    return math;
    
print(to_result());

Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Python doesn’t allow - in variable names. Use _ instead in first-operand-list and second-operator-list

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading