Python Forum

Full Version: Pulling any information from a dictionary with a user input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Sometimes the error is on the line before the line on which it indicates, i.e. on the line before that line254. I would guess you have problem with the closing parenthesis of the dict. here is the whole code with dict created in the code, not using json.

output

Thank you very much! Whatever you've done, you've fixed it! And it looks tidier too, must have been quite tedious!
Was it literally just the matter of indenting it, or have you done some other magic to make it work? Apart from changing the layout, it doesn't really look any different.
As I said, I guess you have problem with the closing brackets. indentation within the dict does not matter. It is only for readability. If you post your original code I will look into it.
The first code on the post was the original. I found I accidentally removed a closing bracket about half way through the code in (element 67, Holmium) after I made the changes, which was probably the entire reason.
(Nov-22-2017, 11:16 AM)Darmanus Wrote: [ -> ]I tried both of these bits, but anything that I put after the dictionary now returns the following syntax error
I was asking for this code, not the one from very first post
(Nov-22-2017, 02:12 PM)buran Wrote: [ -> ]I was asking for this code, not the one from very first post
Oh, right! Sorry!
periodic_table = {
'H': {'name': 'Hydrogen', 'number': 1, 'Mass': 1.008, 'Type': 'Nonmetal', 'Radioactive': False},
'He': {'name': 'Helium', 'number': 2, 'Mass': 4.003, 'Type': 'Noble Gas', 'Radioactive': False},
'Li': {'name': 'Lithium', 'number': 3, 'Mass': 6.941, 'Type': 'Alkali Metal', 'Radioactive': False},
'Be': {'name': 'Beryllium', 'number': 4, 'Mass': 9.012, 'Type': 'Alkaline Earth', 'Radioactive': False},
'B': {'name': 'Boron', 'number': 5, 'Mass': 10.811, 'Type': 'Semimetal', 'Radioactive': False},
'C': {'name': 'Carbon', 'number': 6, 'Mass': 12.011, 'Type': 'Nonmetal', 'Radioactive': False},
'N': {'name': 'Nitrogen', 'number': 7, 'Mass': 14.007, 'Type': 'Nonmetal', 'Radioactive': False},
'O': {'name': 'Oxygen', 'number': 8, 'Mass': 15.999, 'Type': 'Nonmetal', 'Radioactive': False},
'F': {'name': 'Flourine', 'number': 9, 'Mass': 18.998, 'Type': 'Halogen', 'Radioactive': False},
'Ne': {'name': 'Neon', 'number': 10, 'Mass': 20.180, 'Type': 'Noble Gas', 'Radioactive': False},
'Na': {'name': 'Sodium', 'number': 11, 'Mass': 22.990, 'Type': 'Alkali Metal', 'Radioactive': False},
'Mg': {'name': 'Magnesium', 'number': 12, 'Mass': 24.305, 'Type': 'Alkaline Earth', 'Radioactive': False},
'Al': {'name': 'Aluminium', 'number': 13, 'Mass': 26.982, 'Type': 'Basic Metal', 'Radioactive': False},
'Si': {'name': 'Silicon', 'number': 14, 'Mass': 28.086, 'Type': 'Semimetal', 'Radioactive': False},
'P': {'name': 'Phosphorus', 'number': 15, 'Mass': 30.974, 'Type': 'Nonmetal', 'Radioactive': False},
'S': {'name': 'Sulphur', 'number': 16, 'Mass': 32.066, 'Type': 'Nonmetal', 'Radioactive': False},
'Cl': {'name': 'Chlorine', 'number': 17, 'Mass': 35.453, 'Type': 'Halogen', 'Radioactive': False},
'Ar': {'name': 'Argon', 'number': 18, 'Mass': 39.948, 'Type': 'Noble Gas', 'Radioactive': False},
'K': {'name': 'Potassium', 'number': 19, 'Mass': 39.098, 'Type': 'Alkali Metal', 'Radioactive': False},
'Ca': {'name': 'Calcium', 'number': 20, 'Mass': 40.078, 'Type': 'Alkaline Earth', 'Radioactive': False},
'Sc': {'name': 'Scandium', 'number': 21, 'Mass': 44.956, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ti': {'name': 'Titanium', 'number': 22, 'Mass': 47.867, 'Type': 'Transistion Metal', 'Radioactive': False},
'V': {'name': 'Vanadium', 'number': 23, 'Mass': 50.942, 'Type': 'Transistion Metal', 'Radioactive': False},
'Cr': {'name': 'Chromium', 'number': 24, 'Mass': 51.996, 'Type': 'Transistion Metal', 'Radioactive': False},
'Mn': {'name': 'Manganese', 'number': 25, 'Mass': 54.938, 'Type': 'Transistion Metal', 'Radioactive': False},
'Fe': {'name': 'Iron', 'number': 26, 'Mass': 55.845, 'Type': 'Transistion Metal', 'Radioactive': False},
'Co': {'name': 'Cobalt', 'number': 27, 'Mass': 58.693, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ni': {'name': 'Nickel', 'number': 28, 'Mass': 58.693, 'Type': 'Transistion Metal', 'Radioactive': False},
'Cu': {'name': 'Copper', 'number': 29, 'Mass': 63.546, 'Type': 'Transistion Metal', 'Radioactive': False},
'Zn': {'name': 'Zinc', 'number': 30, 'Mass': 65.38, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ga': {'name': 'Gallium', 'number': 31, 'Mass': 69.723, 'Type': 'Basic Metal', 'Radioactive': False},
'Ge': {'name': 'Germanium', 'number': 32, 'Mass': 72.631, 'Type': 'Semimetal', 'Radioactive': False},
'As': {'name': 'Arsenic', 'number': 33, 'Mass': 74.922, 'Type': 'Semimetal', 'Radioactive': False},
'Se': {'name': 'Selenium', 'number': 34, 'Mass': 78.972, 'Type': 'Nonmetal', 'Radioactive': False},
'Br': {'name': 'Bromine', 'number': 35, 'Mass': 79.904, 'Type': 'Halogen', 'Radioactive': False},
'Kr': {'name': 'Krypton', 'number': 36, 'Mass': 84.798, 'Type': 'Noble Gas', 'Radioactive': False},
'Rb': {'name': 'Rubidium', 'number': 37, 'Mass': 85.468, 'Type': 'Alkali Metal', 'Radioactive': False},
'Sr': {'name': 'Strontium', 'number': 38, 'Mass': 87.62, 'Type': 'Alkaline Earth', 'Radioactive': False},
'Y': {'name': 'Yttrium', 'number': 39, 'Mass': 88.906, 'Type': 'Transistion Metal', 'Radioactive': False},
'Zr': {'name': 'Zirconium', 'number': 40, 'Mass': 91.224, 'Type': 'Transistion Metal', 'Radioactive': False},
'Nb': {'name': 'Niobium', 'number': 41, 'Mass': 92.906, 'Type': 'Transistion Metal', 'Radioactive': False},
'Mo': {'name': 'Molybdenum', 'number': 42, 'Mass': 95.95, 'Type': 'Transistion Metal', 'Radioactive': False},
'Tc': {'name': 'Technetium', 'number': 43, 'Mass': 98.907, 'Type': 'Transistion Metal', 'Radioactive': True},
'Ru': {'name': 'Ruthenium', 'number': 44, 'Mass': 101.07, 'Type': 'Transistion Metal', 'Radioactive': False},
'Rh': {'name': 'Rhodium', 'number': 45, 'Mass': 102.906, 'Type': 'Transistion Metal', 'Radioactive': False},
'Pd': {'name': 'Palladium', 'number': 46, 'Mass': 106.42, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ag': {'name': 'Silver', 'number': 47, 'Mass': 107.868, 'Type': 'Transistion Metal', 'Radioactive': False},
'Cd': {'name': 'Cadmium', 'number': 48, 'Mass': 112.411, 'Type': 'Transistion Metal', 'Radioactive': False},
'In': {'name': 'Indium', 'number': 49, 'Mass': 114.818, 'Type': 'Basic Metal', 'Radioactive': False},
'Sn': {'name': 'Tin', 'number': 50, 'Mass': 118.711, 'Type': 'Basic Metal', 'Radioactive': False},
'Sb': {'name': 'Antimony', 'number': 51, 'Mass': 121.760, 'Type': 'Semimetal', 'Radioactive': False},
'Te': {'name': 'Tellurium', 'number': 52, 'Mass': 127.6, 'Type': 'Semimetal', 'Radioactive': False},
'I': {'name': 'Iodine', 'number': 53, 'Mass': 126.904, 'Type': 'Halogen', 'Radioactive': False},
'Xe': {'name': 'Xenon', 'number': 54, 'Mass': 131.294, 'Type': 'Noble Gas', 'Radioactive': False},
'Cs': {'name': 'Cesium', 'number': 55, 'Mass': 132.905, 'Type': 'Alkali Metal', 'Radioactive': False},
'Ba': {'name': 'Barium', 'number': 56, 'Mass': 137.328, 'Type': 'Alkaline Earth', 'Radioactive': False},
'La': {'name': 'Lanthanum', 'number': 57, 'Mass': 138.905, 'Type': 'Lanthanide', 'Radioactive': False},
'Ce': {'name': 'Cerium', 'number': 58, 'Mass': 140.116, 'Type': 'Lanthanide', 'Radioactive': False},
'Pr': {'name': 'Praseodymium', 'number': 59, 'Mass': 140.908, 'Type': 'Lanthanide', 'Radioactive': False},
'Nd': {'name': 'Neodymium', 'number': 60, 'Mass': 144.242, 'Type': 'Lanthanide', 'Radioactive': False},
'Pm': {'name': 'Prometheum', 'number': 61, 'Mass': 144.913, 'Type': 'Lanthanide', 'Radioactive': True},
'Sm': {'name': 'Samarium', 'number': 62, 'Mass': 150.36, 'Type': 'Lanthanide', 'Radioactive': False},
'Eu': {'name': 'Europium', 'number': 63, 'Mass': 151.964, 'Type': 'Lanthanide', 'Radioactive': False},
'Gd': {'name': 'Gadolinium', 'number': 64, 'Mass': 157.25, 'Type': 'Lanthanide', 'Radioactive': False},
'Tb': {'name': 'Terbuim', 'number': 65, 'Mass': 158.925, 'Type': 'Lanthanide', 'Radioactive': False},
'Dy': {'name': 'Dysprosium', 'number': 66, 'Mass': 162.500, 'Type': 'Lanthanide', 'Radioactive': False},
'Ho': {'name': 'Holmium', 'number': 67, 'Mass': 164.930, 'Type': 'Lanthanide', 'Radioactive': False,
'Er': {'name': 'Erbium', 'number': 68, 'Mass': 167.259, 'Type': 'Lanthanide', 'Radioactive': False},
'Tm': {'name': 'Thulium', 'number': 69, 'Mass': 168.934, 'Type': 'Lanthanide', 'Radioactive': False},
'Yb': {'name': 'Ytterbium', 'number': 70, 'Mass': 173.055, 'Type': 'Lanthanide', 'Radioactive': False},
'Lu': {'name': 'Lutetium', 'number': 71, 'Mass': 174.967, 'Type': 'Lanthanide', 'Radioactive': False},
'Hf': {'name': 'Hafnium', 'number': 72, 'Mass': 178.49, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ta': {'name': 'Tantalum', 'number': 73, 'Mass': 180.948, 'Type': 'Transistion Metal', 'Radioactive': False},
'W': {'name': 'Tungsten', 'number': 74, 'Mass': 183.84, 'Type': 'Transistion Metal', 'Radioactive': False},
'Re': {'name': 'Rhenium', 'number': 75, 'Mass': 186.207, 'Type': 'Transistion Metal', 'Radioactive': False},
'Os': {'name': 'Osmium', 'number': 76, 'Mass': 190.23, 'Type': 'Transistion Metal', 'Radioactive': False},
'Ir': {'name': 'Iridium', 'number': 77, 'Mass': 192.217, 'Type': 'Transistion Metal', 'Radioactive': False},
'Pt': {'name': 'Platinum', 'number': 78, 'Mass': 195.085, 'Type': 'Transistion Metal', 'Radioactive': False},
'Au': {'name': 'Gold', 'number': 79, 'Mass': 196.967, 'Type': 'Transistion Metal', 'Radioactive': False},
'Hg': {'name': 'Mercury', 'number': 80, 'Mass': 200.592, 'Type': 'Transistion Metal', 'Radioactive': False},
'Tl': {'name': 'Thallium', 'number': 81, 'Mass': 204.383, 'Type': 'Basic Metal', 'Radioactive': False},
'Pb': {'name': 'Lead', 'number': 82, 'Mass': 207.2, 'Type': 'Basic Metal', 'Radioactive': False},
'Bi': {'name': 'Bismuth', 'number': 83, 'Mass': 208.980, 'Type': 'Basic Metal', 'Radioactive': True},
'Po': {'name': 'Polonium', 'number': 84, 'Mass': 208.982, 'Type': 'Semimetal', 'Radioactive': True},
'At': {'name': 'Astatine', 'number': 85, 'Mass': 209.987, 'Type': 'Halogen', 'Radioactive': True},
'Rn': {'name': 'Radon', 'number': 86, 'Mass': 222.018, 'Type': 'Noble Gas', 'Radioactive': True},
'Fr': {'name': 'Francium', 'number': 87, 'Mass': 223.020, 'Type': 'Alkali Metal', 'Radioactive': True},
'Ra': {'name': 'Radium', 'number': 88, 'Mass': 226.025, 'Type': 'Alkaline Earth', 'Radioactive': True},
'Ac': {'name': 'Actinium', 'number': 89, 'Mass': 227.028, 'Type': 'Actinide', 'Radioactive': True},
'Th': {'name': 'Thorium', 'number': 90, 'Mass': 232.038, 'Type': 'Actinide', 'Radioactive': True},
'Pa': {'name': 'Protactinium', 'number': 91, 'Mass': 231.036, 'Type': 'Actinide', 'Radioactive': True},
'U': {'name': 'Uranium', 'number': 92, 'Mass': 238.029, 'Type': 'Actinide', 'Radioactive': True},
'Np': {'name': 'Neptunium', 'number': 93, 'Mass': 237.048, 'Type': 'Actinide', 'Radioactive': True},
'Pu': {'name': 'Plutonium', 'number': 94, 'Mass': 244.064, 'Type': 'Actinide', 'Radioactive': True},
'Am': {'name': 'Americium', 'number': 95, 'Mass': 243.061, 'Type': 'Actinide', 'Radioactive': True},
'Cm': {'name': 'Curium', 'number': 96, 'Mass': 247.070, 'Type': 'Actinide', 'Radioactive': True},
'Bk': {'name': 'Berkelium', 'number': 97, 'Mass': 247.070, 'Type': 'Actinide', 'Radioactive': True},
'Cf': {'name': 'Californium', 'number': 98, 'Mass': 251.080, 'Type': 'Actinide', 'Radioactive': True},
'Es': {'name': 'Einsteinium', 'number': 99, 'Mass': 254, 'Type': 'Actinide', 'Radioactive': True},
'Fm': {'name': 'Fermium', 'number': 100, 'Mass': 257.095, 'Type': 'Actinide', 'Radioactive': True},
'Md': {'name': 'Mendelevium', 'number': 101, 'Mass': 258.1, 'Type': 'Actinide', 'Radioactive': True},
'No': {'name': 'Nobelium', 'number': 102, 'Mass': 259.101, 'Type': 'Actinide', 'Radioactive': True},
'Lr': {'name': 'Lawrencium', 'number': 103, 'Mass': 262, 'Type': 'Actinide', 'Radioactive': True},
'Rf': {'name': 'Rutherfordium', 'number': 104, 'Mass': 261, 'Type': 'Transistion Metal', 'Radioactive': True},
'Db': {'name': 'Dubnium', 'number': 105, 'Mass': 262, 'Type': 'Transistion Metal', 'Radioactive': True},
'Sg': {'name': 'Seaborgium', 'number': 106, 'Mass': 266, 'Type': 'Transistion Metal', 'Radioactive': True},
'Bh': {'name': 'Bohrium', 'number': 107, 'Mass': 264, 'Type': 'Transistion Metal', 'Radioactive': True},
'Hs': {'name': 'Hassnium', 'number': 108, 'Mass': 269, 'Type': 'Transistion Metal', 'Radioactive': True},
'Mt': {'name': 'Meitnerium', 'number': 109, 'Mass': 268, 'Type': 'Transistion Metal', 'Radioactive': True},
'Ds': {'name': 'Darmstadium', 'number': 110, 'Mass': 269, 'Type': 'Transistion Metal', 'Radioactive': True},
'Rg': {'name': 'Roetgenium', 'number': 111, 'Mass': 272, 'Type': 'Transistion Metal', 'Radioactive': True},
'Cn': {'name': 'Copernicium', 'number': 112, 'Mass': 277, 'Type': 'Transistion Metal', 'Radioactive': True},
'Nh': {'name': 'Nihonium', 'number': 113, 'Mass': 'Unknown', 'Type': 'Basic Metal', 'Radioactive': True},
'Fl': {'name': 'Ferovium', 'number': 114, 'Mass': 289, 'Type': 'Basic Metal', 'Radioactive': True},
'Mc': {'name': 'Moscovium', 'number': 115, 'Mass': 'Unknown', 'Type': 'Basic Metal', 'Radioactive': True},
'Lv': {'name': 'Livermorium', 'number': 116, 'Mass': 298, 'Type': 'Basic Metal', 'Radioactive': True},
'Ts': {'name': 'Tennessine', 'number': 117, 'Mass': 'Unknown', 'Type': 'Halogen', 'Radioactive': True},
'Og': {'name': 'Oganesson', 'number': 118, 'Mass': 'Unknown', 'Type': 'Noble Gas', 'Radioactive': True}}
This is the code after I made the changes and before I found the missing bracket, I put it into a JSON Formatter and that's how I found it.
I have amended it now.
you still have missing bracket on line#68, at the end, after False. That is why it gives you Syntax Error
Don't forget to look at post 6.

You may want to get an idea of how Paul Kienzle did it.
That looks pretty cool to be fair. There's loads of stuff on that site that I hadn't even thought of doing. For now, though, I just wanted to give it a go and see what mistakes I made so that I could learn from them. That's why I didn't want to use the JSON file. I am currently working on it a bit more, making it interactive so that a user can type in such things as atomic numbers and symbols and have the program return the relevant data. Thanks for the help, guys!
I understand, but if you want to peek at the code, you can download the source code here: https://pypi.python.org/packages/7d/6e/2...7fd8341b6f
Pages: 1 2