Skip to content

Commit

Permalink
range updated to get odd numbers between 1 and max number
Browse files Browse the repository at this point in the history
  • Loading branch information
Aravinth-T committed Jul 8, 2021
1 parent f167a92 commit fd97ca9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data_structures/2_Arrays/Solution/3_odd_even_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

odd_numbers = []

for i in range(max):

This comment has been minimized.

Copy link
@SachinMishra-ux

SachinMishra-ux Aug 8, 2021

we can check for even numbers also. right?
like for i in range(max):
if i%2!=0:
odd_numbers.append(i)

if i%2 == 1:
for i in range(1, max):
if i % 2 == 1:
odd_numbers.append(i)

print("Odd numbers: ",odd_numbers)
print("Odd numbers: ", odd_numbers)

3 comments on commit fd97ca9

@Israelite100
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I used a different method.

for i in range(1, max):
if i % 2 != 0:
Odd.append(i)
Print(odd)

@DominicMukilan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a 1 to max in range to print max num if it is odd.

@kokanemanoj1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_number1=int(input("Please enter the max_number"))
odd_numbers1=[item for item in range(1,max_number1) if item%2!=0]
print(odd_numbers1)

Please sign in to comment.