Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #defines a function called list
- def list():
- #sets the sum of the list to 0
- sumlist = 0
- #sets the counter to 1
- counter = 1
- #Creates a while loop using the counter
- while counter == 1:
- #allows the user to enter a input
- N = int(input("Enter a number: "))
- #sets the average range from 1 to the number up by two
- avgrng = range(1, N + 1, 2)
- #Sets the range from 1 to the number
- for i in range(1, N + 1):
- #If the number is divisible by two then it is considered even and is not counted
- if i % 2 == 0:
- continue
- #if not then it adds to the total
- else:
- sumlist += i
- #creates the average number by dividing the total sum of the list by numbers taken out of the range
- average = sumlist / len(avgrng)
- #Prints the total to two decimal places
- print('The sum is %.2f' % (sumlist))
- #Prints the sum to two decimal places
- print('The average is %.2f' % (average))
- break
- #Calling the function
- list()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement