Skip to main content

Command Palette

Search for a command to run...

Basics of Python-12

Published
2 min read
Basics of Python-12
P

Hello, I'm Priya Chakraborty, a dedicated B.Tech student in Electrical Engineering at Siliguri Institute Of Technology. I'm an enthusiastic learner, constantly seeking to expand my skill set and knowledge base. With a solid foundation in programming languages such as C, R, Python, and MySQL, I'm poised to tackle complex technical challenges.

But my passions extend beyond the realm of engineering. I'm also an aspiring content writer, driven by a curiosity to communicate ideas, both technical and non-technical, in a way that captivates and educates.

My journey is defined by a relentless pursuit of self-improvement, coupled with strong communication skills. I believe in the power of continuous learning and the importance of sharing knowledge.

Day-12

While loop :

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

the basic syntax of the while loop :

while(expression):

statement (T)

Let's solve a few problems on the while loop:-

  1. Write a program to print 1 to 10 numbers using a while loop :
num = 1

while num <= 10:
    print(num)
    num += 1

output :

1
2
3
4
5
6
7
8
9
10
  1. Write a program to print odd numbers in a range using a while loop
start = 1
end = 20

while start <= end:
    if start % 2 != 0:
        print(start)
    start += 1

output :

1
3
5
7
9
11
13
15
17
19

These are the basic codes using a while loop:-

  1. Write a Python program to print all even numbers between 1 and 50 using a while loop.

  2. Write a Python program to find the factorial of a number using a while loop.

  3. Write a Python program to reverse a given number using a while loop.

  4. Write a Python program to find the sum of digits in a given number using a while loop.

  5. Write a Python program to check if a given number is a palindrome or not using a while loop.

  6. Write a Python program to find the GCD of two numbers using a while loop.

  7. Write a Python program to print the Fibonacci series up to a given number using a while loop.

  8. Write a Python program to implement a binary search algorithm using a while loop.

  9. Write a Python program to find the largest and smallest elements in a list using a while loop.

  10. Write a Python program to simulate a simple guessing game using a while loop.

In my next blog, you will get to know about python functions.

Thank you !!

More from this blog

Priya's blog

46 posts

Python Developer@Codeclause Mentee @Trailhead Salesforce Content Executive @GDSC SIT'22-23 Google Women Techmakers Ambassador @Google WTM Coreteam @ GirlScript Kolkata

Basics of Python-12