0% found this document useful (0 votes)
20 views16 pages

While Loop Programs With Functions

The document contains a list of 100 programming questions that require the use of while loops in Python. Each question is followed by a template function that includes a placeholder for the logic to be implemented. The questions cover various topics including number series, mathematical operations, and string manipulations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views16 pages

While Loop Programs With Functions

The document contains a list of 100 programming questions that require the use of while loops in Python. Each question is followed by a template function that includes a placeholder for the logic to be implemented. The questions cover various topics including number series, mathematical operations, and string manipulations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

100 While Loop Programs – Questions with

Function-based Python Examples

[Link] a program to print the following using while loop First 10 Even numbers
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] 10 Odd numbers


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q3. First 10 Natural numbers


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q4. First 10 Whole numbers


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q5. Write a program to print first 10 integers and their squares using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q6. Write while loop statement to print the following series: 10, 20, 30 … … 300
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
Q7. Write a while loop statement to print the following series 105, 98, 91 ………7.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q8. Write a program to print the first 10 natural number in reverse order using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q9. Write a program to print sum of first 10 Natural numbers.


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q10. Write a program to print sum of first 10 Even numbers.


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q11. Write a program to print table of a number entered from the user.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q12. Write a program to print all even numbers that falls between two numbers (exclusive both
numbers) entered from the user using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q13. Write a program to check whether a number is prime or not using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q14. Write a program to find the sum of the digits of a number accepted from the user.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q15. Write a program to find the product of the digits of a number accepted from the user.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q16. Write a program to reverse the number accepted from user using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q17. Write a program to display the number names of the digits of a number entered by user, for
example if the number is 231 then output should be Two Three One
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q18. Write a program to print the Fibonacci series till n terms (Accept n from user) using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q19. Write a program to print the factorial of a number accepted from user.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
Q20. Write a program to check whether a number is Armstrong or not. (Armstrong number is a
number that is equal to the sum of cubes of its digits for example : 153 = 1^3 + 5^3 + 3^3.)
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q21. Write a program to add first n terms of the following series using a while loop: 1/1! + 1/2! + 1/3!
+ …….. + 1/n!
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q22. Write a program to enter the numbers till the user wants and at the end it should display the
sum of all the numbers entered.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q23. Write a program to enter the numbers till the user enter ZERO and at the end it should display
the count of positive and negative numbers entered.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q24. Write a program to find the HCF of two numbers entered from the user.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q25. Write a program to convert Decimal to Binary.


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q26. Write a program to convert Binary to Decimal.


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q27. Write a program to check whether a number is palindrome or not.


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q28. Write a python program to sum the sequence: 1 + 1/1! + 1/2! + 1/3! + …….. + 1/n!
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q29. Write a program to accept 10 numbers from the user and display it’s average
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q30. Write a program to accept 10 numbers from the user and display the largest & smallest
number number.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q31. Write a program to display sum of odd numbers and even numbers separately that fall
between two numbers accepted from the user.(including both numbers) using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q32. Write a program to display all the numbers which are divisible by 13 but not by 3 between 100
and 500.(exclusive both numbers)
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q33. Write a program to print the following series till n terms. 2 , 22 , 222 , 2222 _ _ _ _ _ n terms
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q34. Write a program to print the following series till n terms. 1 4 9 16 25 _ _ _ _ _ n terms.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q35. Write a program to find the sum of the following series(accept values of x and n from user) 1 +
x/1! + x2/2! + ……….xn/n!
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q36. Write a program to find the sum of following series : x + x2/2 + ……….xn/n
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q37. Write a program to find the sum of following series 1 + 8 + 27 …………n terms
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q38. Write a program to find the sum of following series: 1 + 2 + 6 + 24 + 120 . . . . . n terms
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
Q39. Write a program to find the sum of following series: S = 1 + 4 – 9 + 16 – 25 + 36 – … … n
terms
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q40. Write a Program to print all the characters in the string ‘PYTHON’ using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q41. Write a program to print only odd numbers from the given list using while loop. L = [23, 45, 32,
25, 46, 33, 71, 90]
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q42. Write a program to print all the factors of a number using while loop.
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q43. Write a python program to get the following output 1—–49 2—–48 3—–47 … … 48—–2
49—–1
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the upper case character from the given string s=input(‘enter the
string:’)
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
[Link] a Program to separate positive and negative number from a list. x = eval(input('enter the
list:'))
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program that appends the type of elements from a list. n = [23, 'Python',23.98]
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q47. Write a program to fetch only even values from a dictionary. dic = {'val1':10, 'val2':20, 'val3':23,
'val4':22 }
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the string data items from the given list only if string is
palindrome
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the special characters from the given string
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the upper case character ,lower case character ,numbers and
special characters into four different output variables from the given string
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output -


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to convert all the lower case charater to upper case characters present in a
given string
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to convert all the lower case character to upper case character and upper
case character to lower case character by keeping number and special character as it is
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the lower case character from the given string only if its ascii
value is even
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=’abcd’ output={‘a’:97,’b’:98,’c’:99,’d’:100}


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=’hello’ output={0:’h’ , 1:’e’ , 2:’l’ , 3:’l’ , 4:’o’}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=[‘hai’ , 89 ,3.4 , ‘hello’ , 90 , ‘py’]
output={‘hai’:’hi’ , ‘hello’:’ho’ , ‘py’:’py’}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=‘hai hello’ output=’olleh iah’
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to count the number of vowels present in a given string


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=‘hai hello good morning’ output={‘hai’:’a’ ,
‘hello’: ‘l’ , ‘good’:’gd’ , ‘morning’:’n’}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=[‘[Link]’ , ’[Link]’ , ‘[Link]’]


output=[‘com’ , ’py’ , ‘html’]
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input=[‘[Link]’ , ’[Link]’ , ‘[Link]’ ,


‘[Link]’ , ‘[Link]’] output={‘com’:[‘jiocinema’ , ‘amazon’] , ’py’:[ ‘file’ , ‘text’] , ‘html’:[‘web’]}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output(count no of vowels) input=’hai hello’ output={‘hai’:2
, ‘hello’:2}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the string values present in the list collection only if the last
character is upper case. Concatenate the extracted output using ‘*’
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the list data items present in list collection only if it is having
middle value , that value is integer and having even number at start
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input= ‘just looking like wow’ output= ‘jusT
LOOKING Like a wow’
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to find the common elements in two sets using a while loop set1 = {1, 2, 3, 4, 5} set2
= {3, 4, 5, 6, 7}
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to check if a number is a perfect number or not using while loop


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to find the length of the longest substring without repeating characters in a given
string using while loop
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to find the maximum and minimum elements in a tuple using while loop
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to find the union, intersection, and difference of two sets using while loop
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] to count the number of occurrences of each character in a string using a dictionary
and while loop
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to remove duplicate value from collection without converting to set
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to find the length of collection without using len function
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the integers from a list only if the integer is starting from even
number and ending as odd number and having length more than 3
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
[Link] a program to extract all the individual data items of a list if the length of extracted output
is more than 4 print the first value of the output else print last value of the output list and add 10 to it
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to get the following output input1=’11001010’ input2=’01110010’ output=4(to


count how many positions are having same value)
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q80..Write a program to get the following output input=[1,2,3,4,5,6] value=3 output=[1,2,3][4,5,6] If


value=2 output=[1,2][3,4][5,6]
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q81..Write a program to check weather the given number is spy number or not i.e, 1*2*3=1+2+3
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check weather the given number is Xylem number or not i.e, 1234 →
1+4=2+3
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check weather the given number is phloem number or not I.e, 12345→
1+5!=2+3+4
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
[Link] a program to check weather the given number is neon number or not i.e. 9 is number,
9**2=81→8+1=9
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check weather the given number is automorphic or not I.e.5 is number
5**2=25 last digit of 25 is the number itself
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to count number of words in the given string s=input('enter the str:').split()
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to find the length of the longest word


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to count number of consonants in the given string s=input('enter the str:')
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check the type of data entered by the users


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check weather the given tuple is palindrome or not


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to check weather the given collection is having nested collection or not
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q92. Write a program to return the positions of vowels present in the given string
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

Q93:Write a program to find length of collection without using len function


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to whether the entered username and password is correct or not if not correct
print enter again
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all integer data items from tuple


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to extract all the non default values from the list
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()
[Link] a program to get the following output - Input='hai hello how are you'
output='hai**hello**how**are**you'
def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to reverse the given list


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program for number game


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

[Link] a program to print ‘Thank you’ for n times


def program():
# write logic using while loop
i = 0
while i < 10:
print(i)
i += 1

program()

You might also like