0% found this document useful (0 votes)
16 views3 pages

MSBTE Python Loop Programs: 50 Questions

The document contains a list of 50 Python programming questions categorized into three sections: For Loop Programs, While Loop Programs, and Nested Loop Programs. Each section includes various tasks such as printing numbers, calculating factorials, generating Fibonacci series, and creating patterns. The questions are designed to test and enhance programming skills in Python using different types of loops.

Uploaded by

ayushshinde450
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)
16 views3 pages

MSBTE Python Loop Programs: 50 Questions

The document contains a list of 50 Python programming questions categorized into three sections: For Loop Programs, While Loop Programs, and Nested Loop Programs. Each section includes various tasks such as printing numbers, calculating factorials, generating Fibonacci series, and creating patterns. The questions are designed to test and enhance programming skills in Python using different types of loops.

Uploaded by

ayushshinde450
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

MSBTE Python Loop-Based Program Questions (50 Questions)

For Loop Programs (1-20)

1. Print numbers from 1 to 10.

2. Print even numbers between 1 to 50.

3. Print odd numbers from 1 to 100.

4. Print the multiplication table of a number.

5. Calculate factorial of a number.

6. Calculate the sum of numbers from 1 to N.

7. Print reverse of a number.

8. Count digits in a number.

9. Check if a number is prime.

10. Print all prime numbers from 1 to 100.

11. Generate Fibonacci series up to N terms.

12. Print squares of numbers from 1 to N.

13. Find sum of digits of a number.

14. Check if a number is palindrome.

15. Print all Armstrong numbers between 1 and 500.

16. Print characters of a string one by one.

17. Find ASCII value of each character in a string.

18. Print sum of even and odd numbers between 1 and 50.

19. Find the power of a number (x^y).

20. Find GCD (HCF) of two numbers using loop.

While Loop Programs (21-40)

21. Print numbers from 1 to 10 using while loop.

22. Reverse a number using while loop.

23. Count number of digits in a number.


24. Calculate factorial using while loop.

25. Print sum of digits using while loop.

26. Check if a number is palindrome using while loop.

27. Check if a number is an Armstrong number using while loop.

28. Find LCM of two numbers using while loop.

29. Accept numbers until user enters 0 and print sum.

30. Accept numbers until negative number is entered.

31. Print Fibonacci series using while loop.

32. Accept password until it is correct (simulate login).

33. Print alphabets A to Z using while loop.

34. Find average of N numbers entered by the user.

35. Count vowels in a string using while loop.

36. Count frequency of digit 5 in a number.

37. Accept and sum 5 numbers using while loop.

38. Calculate power of number (x^y) without using **.

39. Convert a decimal number to binary using while loop.

40. Sum of even digits of a number using while loop.

Nested Loop Programs (41-50)

41. Print the following pattern:

**

***

****

42. Print pattern:

12
123

1234

43. Print multiplication table from 1 to 5 using nested loops.

44. Print pattern of numbers:

54321

4321

321

21

45. Print pyramid of stars.

46. Print Floyd's triangle.

47. Print pattern:

AB

ABC

ABCD

48. Print table of all numbers from 1 to 10.

49. Count number of words in a sentence using nested loop.

50. Print prime numbers in 2D matrix format using nested loop.

Common questions

Powered by AI

Armstrong numbers are those equal to the sum of their own digits each raised to the power of the number of digits, whereas palindrome numbers read the same forwards and backwards. While loop implementation for an Armstrong number involves calculating powers and summing them, palindrome checking mainly involves reversing the digits and comparing the number to its reverse .

Nested loops for pattern printing, like pyramids or triangles, excel at iterating through and controlling complex arrangements of characters. However, they can lead to increased complexity and readability issues if not managed carefully, especially with higher dimensions or larger iterations .

To calculate the length (i.e., count the digits) of a number, you can use both for and while loops. With a for loop, you can iterate over the digits by first converting the number to a string and using len() to directly count the characters. A while loop is a direct approach where you repeatedly divide the number by 10 and count the iterations until the number becomes zero .

To convert a decimal number to binary using a while loop, continuously divide the number by 2 and record the remainder at each step. Construct the binary number by appending these remainders in reverse order. Continue until the number is reduced to zero .

To check if a number is an Armstrong number using a while loop, you first need to determine the number of digits (n). Then, for each digit, calculate the power of n of that digit and sum these values. Finally, compare this sum with the original number. If they are equal, the number is an Armstrong number .

Simulating a login attempt involves using a while loop to repeatedly prompt for a password. The loop continues until the entered password matches the stored correct password. This approach ensures continuous checking without manual resets .

Nested loops can be used to create number patterns by iterating through rows and columns, printing a specific set of numbers in each iteration. For example, a pattern like 54321, 4321, etc., can be generated by having the outer loop control the starting point (5, then 4, then 3, etc.) and the inner loop control the number of iterations, decrementing each time .

A Fibonacci sequence using a while loop can be generated by starting with two initial variables representing the first two numbers of the series. The loop continues, updating these variables by summing them to generate the next number until reaching the desired position in the sequence .

To print prime numbers from 1 to 100, use a for loop to iterate through each number, checking for primality by seeing if any number up to the square root of the number divides it evenly. If none do besides 1 and itself, it is prime and should be printed .

Using loops to find the GCD involves iterating and repeatedly reducing the larger number by the smaller until both numbers become equal. At this point, the number represents the GCD. This method is practical when handling large sets of data or when the Euclidean algorithm’s recursive implementations are avoided .

You might also like