-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.py
More file actions
34 lines (25 loc) · 1.2 KB
/
day5.py
File metadata and controls
34 lines (25 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#Today's topic covered is mainly about function, there go through about block of code / positional arguments and named arguments / bydefault value of argument if parameter is not passed into the function / documentation strings is a multi line which tells what function is doing.
#Today's 🎯 Challenge
#- Write a function that computes the sum and average of a list of numbers
user_list = []
def sum(num_list,user_choice=sum):
total = 0
i=0
for num in num_list:
i=i+1
total=total+num
if user_choice.lower()=='sum':
return total
elif user_choice.lower()=='avg' or user_choice.lower() == 'average':
return total/i
else:
print('enter proper user choice')
exit()
user_input = int(input('Enter how many number do you want to do? = '))
for i in range(1,user_input+1):
number_input = int(input(f'enter the nubmer {i} here = '))
user_list.append(number_input)
user_choice = input('What calculation you want to perform sum or avg? \n Write it here = ')
user_input_list_total = sum(user_list,user_choice)
if user_input_list_total !=None:
print(f'{user_choice} of list {user_list} is = {user_input_list_total}')