You can use the range() function with a step of 2 to generate odd numbers and then use a loop to print the first 25 odd numbers. Here's a simple Python program to achieve this:
# Using range() to generate the first 25 odd numbers
odd_numbers = list(range(1, 50, 2))[:25]
# Printing the first 25 odd numbers
for number in odd_numbers:
print(number)
In this program:
range(1, 50, 2) generates odd numbers starting from 1, up to, but not including 50, with a step of 2.
[:25] is used to select the first 25 numbers from the list generated by range().
The loop then prints each of the first 25 odd numbers.
0 Comments:
Post a Comment