Python: Associate the average of the numbers from 1 to n (where n is a positive integer value) with the variable avg.
Python code:
#accepting n from user
n=int(input("Enter n: "))
#finding average by summing up all numbers in the range 1 to n and
dividing sum by n and assigning it to avg
avg=sum(range(1,n+1))/n
#printing the average
print("Average is",avg)
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.