Home > Software engineering >  why I am getting errror , what did I do wrong while writing a function [closed]
why I am getting errror , what did I do wrong while writing a function [closed]

Time:09-17

def printSeries(start,end, interval):
    print('\n')
    temp= start
while (temp < end):
    print(temp)
    temp  = interval
printSeries(1,35,5)

Traceback (most recent call last): line 1346, in while (temp < end): NameError: name 'end' is not defined

CodePudding user response:

Here you while loop isn't in the scope of the function. Therefore, the variables passed and in the function cannot be accessed from outside the functions scope, that's why you are getting an error.

def printSeries(start,end, interval):
    print('\n')
    temp = start
    while (temp < end):
        print(temp)
        temp  = interval
printSeries(1,35,5)

CodePudding user response:

def printSeries(start,end, interval):
    temp= start
    while temp < end:
        print(temp),
        temp  = interval
printSeries(5,240,20)
  • Related