178k views
4 votes
write a program that reads a list of integers, and outputs whether the list contains all multiples of 10, no multiples of 10, or mixed values. define a function named is list mult10 that takes a list as a parameter, and returns a boolean that represents whether the list contains all multiples of ten. define a function named is list no mult10 that takes a list as a parameter and returns a boolean that represents whether the list contains no multiples of ten.then, write a main program that takes an integer, representing the size of the list, followed by the list values. the first integer is not in the list.ex: if the input is:

1 Answer

5 votes

Final answer:

The program uses two functions, is_list_mult10 and is_list_no_mult10, to check if a list contains all, none, or a mix of multiples of 10. It reads a size and list of integers from the user and prints the result.

Step-by-step explanation:

Python Program to Check Multiples of 10 in a List

To solve the problem, we need to write a program that determines if a list contains all multiples of 10, no multiples of 10, or a mix of both. We define two functions, is_list_mult10 and is_list_no_mult10, each taking a list as a parameter and returning a boolean.

The is_list_mult10 function checks if every element in the list is a multiple of 10. The is_list_no_mult10 function verifies if there are no multiples of 10 in the list. Finally, the main program reads the input size, followed by the list of integers, and uses these functions to output the appropriate response.

Here is the Python code:

def is_list_mult10(lst):
return all(x % 10 == 0 for x in lst)

def is_list_no_mult10(lst):
return all(x % 10 != 0 for x in lst)

def main():
size = int(input('Enter the size of the list: '))
numbers = []
for i in range(size):
number = int(input('Enter number ' + str(i + 1) + ': '))
numbers.append(number)

if is_list_mult10(numbers):
print('All multiples of 10')
elif is_list_no_mult10(numbers):
print('No multiples of 10')
else:
print('Mixed values')

main()

When running the main program, it prompts for the number of elements and the list items, then prints the result based on the functions' evaluations.

User Jim Speaker
by
9.1k points