SHARE
TWEET

Untitled

a guest Oct 17th, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #defines a function called list
  2. def list():
  3.     #sets the sum of the list to 0
  4.     sumlist = 0
  5.     #sets the counter to 1
  6.     counter = 1
  7. #Creates a while loop using the counter
  8.     while counter == 1:
  9.         #allows the user to enter a input
  10.         N = int(input("Enter a number: "))
  11.         #sets the average range from 1 to the number up by two
  12.         avgrng = range(1, N + 1, 2)
  13.         #Sets the range from 1 to the number
  14.         for i in range(1, N + 1):
  15.             #If the number is divisible by two then it is considered even and is not counted
  16.             if i % 2 == 0:
  17.                 continue
  18.             #if not then it adds to the total
  19.             else:
  20.                 sumlist += i
  21.                 #creates the average number by dividing the total sum of the list by numbers taken out of the range
  22.                 average = sumlist / len(avgrng)
  23.         #Prints the total to two decimal places
  24.         print('The sum is %.2f' % (sumlist))
  25.         #Prints the sum to two decimal places
  26.         print('The average is %.2f' % (average))
  27.         break
  28. #Calling the function
  29. list()
RAW Paste Data
Top