• API
• FAQ
• Tools
• Archive
A Pastebin account makes a great Christmas gift
SHARE
TWEET

# Untitled

a guest Oct 17th, 2017 52 Never
ENDING IN00days00hours00mins00secs

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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top