In: Computer Science
for python 3
a. Ask the user to enter 10 numbers. Each number is stored in a list called myList. Compute and print out the sum and average of the items in the list. Print the numbers that are divisible by 2 from myList.
b. Instead of using a list to store the numbers, create a loop to accept the numbers from the user, and find the average of all the numbers. Hint: use an accumulator to store the numbers that are entered by the user. An accumulator is set to zero before the start of the loop (e.g. total =0).
A.
Required program in python -->
myList=[] #declare an empty list
sum=0 #sum=0
for i in range(0,10): #for loop for i starts from i=0 to i=9
n=int(input("Enter Number: ")) #ask user for number
myList.append(n) #add the number in the list
sum=sum+n #number is added in sum
print(sum) #sum is printed
average=sum/10 #average is taken out
print(average) #average is printed
print("Number divisible by 2 are --> ") #print number divisible
by 2 are
for i in range(0,10): #for loop for i starts from i=0 to i=9
if(myList[i]%2==0): #if element of list is divisible by 2
print(myList[i]) #print the number
B.
Required program in python -->
sum=0 #accumulator is set to 0
for i in range(0,10): #for loop for i starts from i=0 to i=9
n=int(input("Enter Number: ")) #ask user for number
sum=sum+n #number is added in sum
print(sum) #prints the final value of sum
average=sum/10 #average is taken out by dividing the value of sum
by 10
print(average) #print the value of average