Python - Command Line Arguments, Print a Number range


Python - Command Line Arguments, Print a Number range

CODE
import sys #This function accepts 2 parameters. The Starting Number and the Ending Number. def writeNumbers(start, end): #The variable i is initialized with the Starting Number. i = start #The loop handles the printing of numbers from the starting number to the ending number. while(i <= end): print(i) #The variable i is incremented by 1 in order to move to the next number in the next iteration. i = i + 1 #The below statements expect 2 integer arguments from the command line. #If it is not supplied, it will throw errors and should be handled separately. #Gets the 1st argument supplied from the command line and convert to int. start = int(sys.argv[1]) #Gets the 2nd argument supplied from the command line and convert to int. end = int(sys.argv[2]) #This statement invokes the above function with the arguments received from the command line. writeNumbers(start, end);

Comments