Theory of Intelligence
11TH•Computer Science•Python Programming•Question 6

Solution

Write a Python program using a while loop that prints all the odd numbers between 1 and 100. Also, count and print the total number of odd numbers.

Solution

PYTHON
number = 1
count = 0
while number <= 100:
    if number % 2 != 0:
        print(number)
        count += 1
    number += 1
print("Total odd numbers:", count)

The while loop runs from 11 to 100100. Each odd number is printed, and count records how many odd numbers there are. There are 5050 odd numbers between 11 and 100100.

Discuss theoretical concepts, mathematical formulas, and architectural foundations.

Supports inline code with `backticks`
No comments yet. Be the first to start the discussion!