Simple Data Types in Python
Write a program that reads a positive integer, , entered by the user and then displays on the screen the sum of all integers from 1 to . The sum of the positive first integers can be calculated as follows: Sum =n(n+1)/2.
n = int(input("Enter an integer: ")) sum = n * (n + 1) / 2 print("The sum of the first integers from 1 to " + str(n) + " is " + str(sum))
Hope You will learn Something. Happy Coding.