r/pythonhelp • u/[deleted] • Oct 16 '20
Help
If someone chose the number 3, how would I make a code that chooses all the positive integers from 1 to n (3), and displays the sum of the numbers? So for example 3, 1+2+3=6(sum)
4
Upvotes
5
u/WhenRedditFlies Oct 16 '20
For anyone who wants a quick answer:
n = int(input("enter a number: "))numbers = range(1, n+1)total = sum(numbers)print(total)