pythonpython-2.7

How to add a set of numbers that the user inputted in Python?


How do I add numbers in between two numbers the user inputted in Python 2.7. So a person would input 75 and 80 and I want my program to add the numbers in between those two numbers. I am very new to programming and python so any help would be awesome!


Solution

  • This example excludes 75 and 80. If you need to include them replace with print sum(range(n1,n2+1))

    n1=input('Enter first number ')
    n2=input('Enter second number ')
    print sum(range(min(n1,n2)+1,max(n1,n2)))