Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to print all odd numbers in a range

# Python program to print Even Numbers in given range
 
start = int(input("Enter the start of range: "))
end = int(input("Enter the end of range: "))
 
#create a list that contains only Even numbers in given range
even_list = range(start, end + 1)[start%2::2]
 
for num in even_list:
    print(num, end = " ")
Comment

Python program to print all even numbers in a range

for num in range(4,15,2):
  #here inside range function first no dentoes starting, second denotes end and third denotes the interval
    print(num)
Comment

Python program to print all odd numbers in a range

# Python program to print odd Numbers in given range
 
start, end = 4, 19
 
# iterating each number in list
for num in range(start, end + 1):
     
    # checking condition
    if num % 2 != 0:
        print(num, end = " ")
Comment

Python program to print all even numbers in a range

# Python program to print Even Numbers in given range
 
start = int(input("Enter the start of range: "))
end = int(input("Enter the end of range: "))
 
#creating even starting range
start = start+1 if start&1 else start
  
 
#create a list and printing element
#contains Even numbers in range
[ print( x ) for x in range(start, end + 1, 2)]
Comment

Python program to print all odd numbers in a range

# Python program to print odd Numbers in a List
  
# list of numbers
list1 = [10, 21, 4, 45, 66, 93]
i = 0
  
# using while loop        
while(i < len(list1)):
      
    # checking condition
    if list1[i] % 2 != 0:
        print(list1[i], end = " ")
      
    # increment i  
    i += 1
Comment

PREVIOUS NEXT
Code Example
Python :: Date Time split in python 
Python :: convert 1 to "one" python 
Python :: date-fns difference in days 
Python :: how to check if a list is nested or not 
Python :: dockerfile for django project 
Python :: python slicing nested list 
Python :: python find duplicates in string 
Python :: python socket recv set timeout 
Python :: python define an array of dictonary 
Python :: print column in pandas 
Python :: url settings 
Python :: matplotlib point labels 
Python :: pandas datetime from date month year columns 
Python :: python parentheses 
Python :: python acf and pacf code 
Python :: length of set python 
Python :: python variables in multiline string 
Python :: odd or even python 
Python :: how to hide tensorflow warnings 
Python :: python merge pdf files into one 
Python :: levenshtein distance 
Python :: how to count number of columns in dataframe python 
Python :: django check user admin 
Python :: python how to remove item from list 
Python :: while loop python 
Python :: check python version windows 
Python :: python aes encryption 
Python :: merge subplot matplotlib 
Python :: sum first 100 integers in python 
Python :: dataframe select data type 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =