Finding out the battery life of arduino?

My question is pretty simple. I just want to know if there is a simple way in the arduino code to find out what the battery power is at and then print it into the serial? Like, find out what the battery life is currently, and then say it's at like 70% power, print 70% to the serial? Cheers.

If your Arduino is running through a voltage regulator or you have an arduino with a 3.3V regulator, you can measure the battery voltage via a voltage divider. From the battery voltage, and knowing the battery type, you can make an estimate of the battery state of charge.

The question is, indeed, very simple, but the answer is that batteries are not like fuel tanks. There is no simple answer, and depends on many factors.