-1

Why does loop_print() produce no output when run in a command prompt, python loops.py 5 10?

import sys

def loop_print(arg1, arg2): # print series between arg1 and arg2
    """Print a series of numbers."""

    while arg1 < arg2:
        print(arg1, end=' ')
        arg1 += 1

if __name__ == "__main__":
    loop_print(sys.argv[1], sys.argv[2])
khelwood
  • 55,782
  • 14
  • 81
  • 108

1 Answers1

0

You've got no output because sys.argv is an array of str. In other words: '5' < '10'? False. It never enters inside the while loop. You must do a cast:

...
loop_print(int(sys.argv[1]), int(sys.argv[2]))
santo
  • 418
  • 1
  • 3
  • 13