Artificial Intelligence can do many things, but there is a set of things that it cannot do. Writing code is definitely one of the things that an AI system can do as shown by Microsoft researchers in their DeepCoder problem. This tool has the ability to write a working piece of code after searching through a database of code and understanding it. As of now, it cannot devise the code from scratch, but it has a good ability to understand the already existing pieces of code and rearrange it or slightly modify it to make it function. However, in the near future, AI systems might develop the ability to generate their own codes, which may or may not be more efficient as compared to the human-written codes.
If you are looking for an online course to learn Artificial Intelligence, check out this Artificial Intelligence Course by Intellipaat.