From 1e9ef3dca7b42246098c83cb58f184d4c8910858 Mon Sep 17 00:00:00 2001 From: "Aribaskar.j.b" Date: Tue, 16 May 2023 18:10:07 +0530 Subject: [PATCH] 3_odd_even_numbers.py code optimized --- .../2_Arrays/Solution/3_odd_even_numbers.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/data_structures/2_Arrays/Solution/3_odd_even_numbers.py b/data_structures/2_Arrays/Solution/3_odd_even_numbers.py index ec1c4b7..08bc290 100644 --- a/data_structures/2_Arrays/Solution/3_odd_even_numbers.py +++ b/data_structures/2_Arrays/Solution/3_odd_even_numbers.py @@ -1,9 +1,20 @@ +# max = int(input("Enter max number: ")) + +# odd_numbers = [] + +# for i in range(1, max): +# if i % 2 == 1: +# odd_numbers.append(i) + +# print("Odd numbers: ", odd_numbers) + max = int(input("Enter max number: ")) odd_numbers = [] +count = 1 -for i in range(1, max): - if i % 2 == 1: - odd_numbers.append(i) +for i in range(max/2): + odd_numbers.append(count) + count += 2 -print("Odd numbers: ", odd_numbers) +print("Odd numbers: ", odd_numbers) \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy