0

I'm a begginer and I am trying to recreate the modern periodic table in Python. For some reason, it shows a syntax error for my elif statement which seems to be perfectly fine to me. I use VS Code as my primary editor, so I copy pasted the code to sublime text and even it shows the same issue. Can anyone identify the isuue and help me fix the issue. I've attached the code below and the error it shows.

ERROR:-
'elif e=='Li' or e=='lithium':
    ^
SyntaxError: invalid syntax'Thanks in advance.

CODE:-

elif e=='Li' or e=='lithium':
    from mendeleev import Li
    print('Name: ', Li.name)
    print('Symbol: ', Li.symbol)
    print('Atomic Number: ',Li.atomic_number)
    print('Group:', Li.group)
    print('Period: ', Li.period)
    print('Block: ', Li.block)
    print('Valence Electrons :', Li.nvalence())
    print('Atomic Mass: ', Li.atomic_weight)
    print('Electronic Configuration: ', Li.ec.conf)
    print('E.C in shells:', Li.ec.electrons_per_shell()

Screenshot:

8
  • Please try to create a minimal reproducible example to show us. And please copy-paste the full and complete error output as text into the question. And add a comment in the code on the line where you get the error. Also please take some time to read the help pages, take the SO tour, read How to Ask, as well as this question checklist. Commented Jul 20, 2020 at 8:04
  • send the whole code; in the code you provided there are no errors. Commented Jul 20, 2020 at 8:05
  • You cannot have a elif without an if. Commented Jul 20, 2020 at 8:05
  • 5
    You didnt close your print statement on the previous line, its missing a ) at the end Commented Jul 20, 2020 at 8:06
  • 1
    In addition to what @Code-Apprentice said you might also want to look at a function to print the output so you dont write all the print statements again and again Commented Jul 20, 2020 at 8:16

1 Answer 1

2

Looking at your snapshot it seems you missed a ) every time for your last print statement. look the line above every elif. you can see it :

print('E.C in shells:', Li.ec.electrons_per_shell()   <---- here!

just add a parenthesis.

3
  • if you find this answer useful please accept it as the answer :)
    – hadi
    Commented Jul 20, 2020 at 8:16
  • 1
    Thanks it worked. It was a careless error on my side Commented Jul 20, 2020 at 8:36
  • @PraninEdward And this is the kind of thing that is difficult to see when you've been staring at the same code for a long time. It helps to have another set of eyes. Commented Jul 20, 2020 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.