Problem 7 in Python and C#