WAP to print all odd numbers out of any 20 numbers.
Answers
Answered by
11
l = list()
for i in range(20):
x = int(input("Enter a number: "))
l.append(x)
print()
print()
ol = list()
for i in l:
if i%2 != 0:
ol.append(i)
print("The odd numbers are: ")
for i in ol:
print(i)
You first start a for loop to input the numbers from the user and append it to a declared list. Another list is created. You then start another loop that checks for the numbers' divisibility by 2, and if it isn't divisible by 2, you append it to the new list.
The new list will have all the odd numbers in it.
Similar questions