200k views
5 votes
Write a Python program that asks user for integer input between 0-20 (both included) five times. Every time user enters a number, program adds that number to the previously entered number and also multiply that number with the previous one and print these two outputs. If user enters a number that is outside of the specified range, the program should end with the error message ("end: invalid number"). If the user enters any of the following numbers: 5, 10, or 15, the program will not add or multiply that number with the previous one but continue to ask for user input. Your program at the end should calculate the average of all 5 correct numbers that satisfy all the requirements specified above followed by a message that "program ended". The format of your output should look like: (25 points)

User Bergerg
by
4.8k points

1 Answer

0 votes

Answer:

multiple=1 #to store the multiplication

sum_numbers=0#to store the sum.

c=0#counter

i=0#iterator

while i<6:

num=int(input('Enter number between 0 to 20: \\'))#taking input

if num<0 or num >20:

print("end: invalid number")

break

if num%5==0 and num!=0:#condition

continue

multiple=num*multiple

sum_numbers=sum_numbers+num

c=c+1

i=i+1

avg=sum/c

print("The sum is "+str(sum_numbers))

print("The multiplication is "+str(multiple))

print('The average is '+str(avg))

Step-by-step explanation:

The above written program is in python.I have taken a variable multiple to store the multiplication of the numbers and sum_numbers for storing the sum of the numbers, a variable c as the counter.I have used the while loop in this solution.If the number entered by the user is out of range then coming out of the loop.If the numbers are 5,10 or 15 then again taking the input.In the end calculating the average and printing the sum,multiplication,average.

User Pyg
by
5.2k points