USING 'FOR' LOOP, WRITE A PROGRAM IN PYTHON TO DISPLAY ODD NUMBERS BETWEEN 1 AND 50.USING 'FOR' LOOP, WRITE A PROGRAM IN PYTHON TO DISPLAY ODD NUMBERS BETWEEN 1and50
Answers
Answered by
7
Required Answer:-
Question:
- Using for loop, write a program in Python to display odd numbers between 1 to 50.
Solution:
This is an easy question. Read this post to get your answer.
Here is the program.
# Written by @mr_anindya_adhikari
#Python program to print odd numbers from 1 to 50.
print("Odd numbers from 1 to 50 are as follows....")
for i in range(1,50,2):
print(i,end=" ")
Logic:
Here, i is the loop variable. Initially, the value of i is 1. After each iteration, the value of i is displayed and it's value is incremented by 2.
1 + 2 = 3 which is odd.
3 + 2 = 5 which is also odd.
In this way, the program works.
Output is attached.
Attachments:
Answered by
3
Question:-
- To display odd numbers between 1 and 50Condition:-Use for loop in python
__________
Code:-
for i in range (1,50,2):
print (i,end=",")
____________
Explanation:
- This program is to print odd numbers between 1 to 50
- in this code, i loop iterates from 1 to 49.
- it is written "print(i,end=",") " so that i can print the odd numbers with comma(,)....it is also used to print the values in same lines....to print in separate lines....you can just write print(i)
- Each iteration is running 2 step forward starting from 1 that is 1,3,5...like this.....so the control will print odd numbers only.
_________
•Output Attached
Attachments:
Similar questions