Try the following (after you selected a layer)
Be aware that we use as an input a layer using EPSG:4326 (hence, the buffer 0.2 degrees = around 20km depending where you are on the globe). The buffer
function uses units from the geometry SRS. You may need to reproject (good thing to learn for your "homework")
layer = iface.activeLayer()
# layer = QgsVectorLayer("path/to/layer", "polygon", "ogr")
feats = [QgsFeature(feat) for feat in layer.getFeatures()]
new_feats = []
for feat in feats:
geom = feat.geometry()
feat.setGeometry(geom.buffer(0.2, 8))
new_feats.append(feat)
mem_layer = QgsVectorLayer("Polygon?crs=epsg:4326", "duplicated_layer", "memory")
mem_layer_data = mem_layer.dataProvider()
attr = layer.dataProvider().fields().toList()
mem_layer_data.addAttributes(attr)
mem_layer.updateFields()
mem_layer_data.addFeatures(new_feats)
QgsProject.instance().addMapLayer(mem_layer)
PS: Code mainly borrowed from Duplicating layer in memory using pyqgis? and adapted
Edit:
For dissolve support, you can take a look at C++ code to see how it works in original processing C++ code you try to avoid ;) https://github.com/qgis/QGIS/blob/master/src/analysis/processing/qgsalgorithmbuffer.cpp.
Be aware that reimplementing all the buffer functionalities in Python is a bit of a waste in fact. The processing buffer was in the "old days" in Python and to speed up has been ported in C++. So, you lose all the benefits with your approach. FYI,you can look at old code buffer.py
(for QGIS 2.18)