Python #6: Takes in user input on a loop then averages the total

#Programmer: Akinwale Owi
#Company Name: Dagba Computers
#Program Purpose: Average User Input

#Beginning of Program

#initializing variable newNumber will hold all the user inputted numbers
newNumber = 0

#initializing total
total = 0

#initializing counter at negative 1 because the last input is the loop breaker
counter = -1

#beginning of while loop that gathers user input
while( newNumber > -1):
newNumber= int(input(‘please enter the next number or a negative number to quit and average’))
total = int(total + newNumber)
counter = counter + 1
#end of while
#when the user breaks the while loop
else:
print(‘number that broke the loop:’)
print(newNumber)
#subtracting the loop breaking number from total
total = total – newNumber
print(‘total of user input:’)
print(total)
print(‘total numbers added to make up the average:’)
print(counter)
#calculating the average
average = total/counter
#printing out the average
print(“the average is:”)
print(average)

#End of Program

————————–Output—————————–

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: