aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/luca-ferrari/python/ch-2.py
blob: 0d36552024a5bb4a1e578ac7d2a7eb16783e194b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!python

#
# Perl Weekly Challenge 333
# Task 2
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-333>
#

import sys

# task implementation
# the return value will be printed
def task_2( args ):
    result = []
    limit  = len( args )
    index  = 0

    while limit > 0:
        current = int( args[ index ] )
        index   = index + 1
        result.append( current )
        limit = limit - 1
        if limit == 0:
            break

        if current == 0:
            result.append( current )
            limit = limit - 1
            if limit == 0:
                break

    return result

# invoke the main without the command itself
if __name__ == '__main__':
    print( task_2( sys.argv[ 1: ] ) )