Doesn't leaving a computer on 24/7 cost more in electricity than the amount of coins gained?
That depends on the equipment you are using, the network difficulty, and the current exchange rate between the bitcoins you earn an the currency you use to pay your electric bill.
The network difficulty and the exchange rate are constantly changing, so you have to keep an eye on them to determine when mining is profitable.