Skip to content

Commit fcf6f12

Browse files
Average challenge solution
This file does not use arrays as they have not been introduced to the class yet.
1 parent dd755ab commit fcf6f12

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

averageMachine

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Create a program that prints an average for a set of
2+
# numbers:
3+
4+
# First, ask the user for how many numbers he would like
5+
# to enter.
6+
7+
# Then ask him to input each number
8+
9+
# Then calculate the average and print it
10+
11+
print('Welcome to my average machine!')
12+
print('Enter in how many numbers you would like to average')
13+
print('n: ')
14+
15+
n = int(input())
16+
17+
totalSum = 0
18+
19+
for i in range(n):
20+
print('Please enter a number: ')
21+
usrInput = int(input())
22+
totalSum = totalSum + usrInput
23+
24+
# totalSum is now all of the numbers added together
25+
26+
average = totalSum / n
27+
28+
print('Your average is: ' + str(average))

0 commit comments

Comments
 (0)