EPAM Systems interview question

Python code using loop of medium difficulty Pyspark code