[Tutor] Adding consecutive numbers

Whom Isac wombingsac at gmail.com
Mon Apr 27 12:37:54 CEST 2015


Hi, I am trying to build a python mini program to solve a math problem . I
wanted my program to ask two number from the operator and it can add those
number as a integer but as consecutive number in range. For example, if
num1 entry =1 & num2 entry = 100 , the program should be adding number from
1 to 100 together(which should equal to 5050). I thought that I could use
range() to use it for any given input from the user. However, there are few
argumentation error and I don't know why my bool function did not work in
while loop. Is there any way to make the program more concise.
I have uploaded my code file below. Please, note that I am fairly new to
programming and donot use complex modules, therefore, suggest me where I
was wrong with the code. I have checked for indentation error, however,
there were no error. So, I don't have any idea about the error.
Thanks.
-------------- next part --------------

##Goal: Building a math program, which allows addition of two numbers in range in consequitive
## sequence e.g. 1+2...+n

if __name__=='__main__':
    interact()

def iteract():
    print('''Welcome to My new Math program!! 
    With this program, you can find the sum of any consequitive numbers.''')
    print('So Just add your numbers in following spaces')
    x =int(input('Please enter your first number: '))
    y =int(input('Please enter your second number: '))
    while True:
        if x<y:
            z = adding_sum_in(x,y)
        else:
            break
    print z


def find_range(x, y):
    x = []
    y = []
    while True:
##        print x.isdigit()
##        print y.isdigit()
       if x.isdigit() == 'True':
            for num in x:
                x.append(num)
       if y.isdigit() == 'True':
            for num in y:
                y.append(num) 
        break
    return R = range({0},{1}).format(x,y)


def adding_sum_in_range(x, y):
    c= find_range(x,y)
    Total_sum = 0
    for i in c:
        Total_sum += i
        return Total_sum
    print(str(Total_sum))
    

'''This is for simple addition function of two numbers:

def addition(x, y):
    num1=(x)
    num2=(y)
return num1+num2

    '''


More information about the Tutor mailing list