Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

while loop odd numbers python

# Python Program to Print Odd Numbers from 1 to N

maximum = int(input(" Please Enter the Maximum Value : "))

number = 1

while number <= maximum:
    if(number % 2 != 0):
        print("{0}".format(number))
    number = number + 1
Comment

Python program to count Even and Odd numbers using while loop in a List

# Python program to count Even and Odd numbers in a List
  
# list of numbers
list1 = [10, 21, 4, 45, 66, 93, 11]
  
even_count, odd_count = 0, 0
num = 0
  
# using while loop     
while(num < len(list1)):
      
    # checking condition
    if list1[num] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
      
    # increment num 
    num += 1
      
print("Even numbers in the list: ", even_count)
print("Odd numbers in the list: ", odd_count)
Comment

PREVIOUS NEXT
Code Example
Python :: create django project 
Python :: even numbers in python 
Python :: numpy sqrt 
Python :: python open directory and read files 
Python :: python requests-session for websites with login 
Python :: decode vnc hash 
Python :: python object of type set is not json serializable 
Python :: flask url_for 
Python :: python new date 
Python :: random.randint 
Python :: python reduce 
Python :: pandas replace nan with value above 
Python :: read parquet from s3 and convert to dataframe 
Python :: create tables with psycopg2 python 
Python :: python dictionary pop 
Python :: pandas read_excel 
Python :: remove decimal python 
Python :: tkinter frameless window 
Python :: arithmetic in python 
Python :: ValueError: query data dimension must match training data dimension 
Python :: django-mathfilters 
Python :: python find string count in str 
Python :: python for loop with index 
Python :: browser = webdriver.firefox() error 
Python :: check for string in list pytho 
Python :: check type of variable in python 
Python :: code for merge sort 
Python :: delete and start fresh with db django 
Python :: pandas write csv 
Python :: python remove 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =