codeFlowType:
codeWrite
codeFlowLang:
Python
Определить, сколько процентов от всего количества элементов последовательности целых чисел составляют нечетные элементы.
numbers = [1,2,3,4,5,6,7,8,9,10]
odd_numbers = []
for number in numbers:
if number % 2 != 0:
odd_numbers.append(number)
percentage = (len(odd_numbers) / len(numbers)) * 100
print("Percentage of odd numbers in the sequence: {}%".format(percentage))
Результат:
Percentage of odd numbers in the sequence: 50.0%