In: Computer Science
PYTHON
Let n denote an integer entered by the user. Write a program to print n multiples of 5 in the descending order, with the last number being 5. Print the average of those n multiples
Source Code:
Output:
Code in text format (See above image of code for indentation):
#list declaration
multiples=[]
#variables
sum=0
c=0
i=0
#read a number from user
n=int(input("Enter a number: "))
while True:
i+=1
#check for multiple of 5
if(i%5==0):
#check for last digit 5
if(i%10==5):
#calculate sum
sum+=i
#add to list
multiples.append(i)
c+=1
#if n multiples are added then break
if(len(multiples)==n):
break
#calculate average
average=sum/c
#sort the list in descending order
multiples.sort(reverse=True)
#print list
print(n," multiples of 5 in the descending order, with the last
number being 5 is:")
print(multiples)
#print average
print("The average is: ",average)