Basics of Python-9

Photo by Chris Ried on Unsplash

Basics of Python-9

Day-9

Loops :

Loops are the controlled structure in the program. There are 2 types of loops in python programming.

  1. For loop

  2. While loop

  3. FOR LOOP :

For loop is used to iterate a sequence of data items.

let's solve a problem on for loop :

a. Write a python program to print 10 numbers using for loop

n=int(input("enter the number"))
for i in range (1,n+1):
    print(i)

output :

  1. WHILE LOOP :

While loop, here the loop will run until the given condition is satisfied.

let's solve a problem on the while loop :

a. Write a python program to print ("Hello world") 3 times using the while loop :

count = 0
while (count < 3):
    count = count + 1
    print("Hello World")

output :

These are the two types of loops in python programming.

Problems :

Write a program in Python to display the Factorial of a number.

Write a program in Python to reverse a word.

Write a Python program to reverse a number.

Write a program to print n natural numbers in descending order using a while loop.

Write a program to display the first 6 multiples of 6

Write a program that appends the type of elements from a list.

Write a program to find and separate even and odd numbers from a list.

Write a program to find only odd values from a dictionary.

In my next blog, You will get to know in brief about these loops.

Thank you !!