Periodic Table of Elements Step 14

Hello everyone,
I’ve been stuck on this one for quite a while now:

  • You should remove all the trailing zeros after the decimals from each row of the atomic_mass column. You may need to adjust a data type to DECIMAL for this. The final values they should be are in the atomic_mass.txt file
    What do I do?
    element.sh:
#! /bin/bash

PSQL="psql --username=freecodecamp --dbname=periodic_table -t --tuples-only -c"

echo -e "\n\n~~~~ Periodic Table ~~~~\n\n"

if [[ -z $1 ]]
then
  echo -e "\nPlease provide an element as an argument."
  exit
fi

#if argument is atomic number
if [[ $1 =~ ^[1-9]+$ ]]
then
  element=$($PSQL "select atomic_number, name, symbol, type, atomic_mass, melting_point_celsius, boiling_point_celsius from elements join properties using(atomic_number) join types using(type_id) where atomic_number = '$1'")
else
#if argument is string
  element=$($PSQL "select atomic_number, name, symbol, type, atomic_mass, melting_point_celsius, boiling_point_celsius from elements join properties using(atomic_number) join types using(type_id) where name = '$1' or symbol = '$1'")
fi

#element not in db
if [[ -z $element ]]
then
  echo -e "\nI could not find that element in the database."
  exit
fi

echo $element | while IFS=" |" read an name symbol type mass mp bp 
do
  echo -e "\nThe element with atomic number $an is $name ($symbol). It's a $type, with a mass of $mass amu. $name has a melting point of $mp celsius and a boiling point of $bp celsius."
done

This is my first time I did this so tell me if I need to add something else please
Wrong code sorry

Welcome to the forum @fdjskalfds

You can manually remove the trailing zeros from the table.
You do not need to include this in your script.

Happy coding

Does that mean a certain part or all of it?

I removed all the trailing zeros from atomic-mass.

If you want, you could include code in the script to update the table.
Then run the script once, check the table updated correctly, then comment out that code.

Which part do I comment out?

Ok, never mind. I was able to get past it and move forward. Thank you for your help!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.