Computer Science, asked by becyber, 4 months ago

1) Write a Python program to print the odd numbers from the following list using for
loop.
List of numbers: 10, 21, 66, 93

Answers

Answered by pramodnagarcuraj17
7

Answer:

# Python program to print odd Numbers in a List

# list of numbers

list1 = [10, 21, 66, 93]

# iterating each number in list

for num in list1:

# checking condition

if num % 2 != 0:

print(num, end = " ")

output

21 93

Answered by Oreki
9

\textsf{\large \textbf{One-Liner}}

  \texttt{print(`Sum of odd elements -',}\\\texttt{\hspace{7em} *[i for i in [10, 21, 66, 93] if i \% 2 != 0])}

\textsf{\large \textbf{Detailed}}

  \texttt{lst = [10, 21, 66, 93]}\\\\\texttt{print("Odd elements -", end=" ")}\\\texttt{for element in lst:}\\\texttt{\hspace{1em} if element \% 2 != 0:}\\\texttt{\hspace{2.4em} print(element, end=" ")}

\textsf{\large \textbf{After Execution}}

  \texttt{Odd elements - 21 93}

Similar questions
Math, 2 months ago