Python Coding Questions – Part 1
INSTRUCTIONS
• Difficulty Level: Easy to Moderate
• Use only conditional and loop structures to develop logical programming skills.
Avoid using data structures like arrays.
• Do not use standard functions, except for basic input and output statements.
• Avoid copying from others or referring to AI tools. The goal is to build your
programming skills. Avoid solving through group-discussions.
• If you are not able to find an answer, it is ok leave that question or get it
partially completed.
• Each program may be structured like a function with a wrapper code that takes an
input (e.g., 3) and executes the corresponding code for question #3.
• Once all questions are attempted, copy all the code into a PDF file, email to
[email protected] with subject line “Python Coding Questions – Part 1”
• There is no deadline for submission due to your exam schedule. However, those who
submit early will receive Part 2 questions to solve.
• We hope you enjoy solving these questions. All the Best.
1. Print the numbers in the pattern shown 1 2 3 4 5
for input n. sample output given when 1 * 2 * 3 * 4 * 5
n = 5
2. Print the numbers in the following 5 4 3 2 1
pattern for input n. sample output 5 * 4 * 3 * 2 * 1
given when n = 5
3. Print the numbers in pattern shown for 1 1 1 1 1
input n. sample output given when n = 2 3 4 5 6
5 3 6 10 15 21
4 10 20 35 56
5 15 35 70 126
4. Print the numbers in the pattern shown 1 *
for input n. sample output given when 2 **
n = 5 3 ***
4 ****
5 *****
5. Print the numbers in the pattern shown 5 *****
for input n. sample output given when 4 ****
n = 5 3 ***
2 **
1 *
6. Print the numbers in the pattern shown 1 ****
for input n. sample output given when 2 ***
n = 5 3 **
4 *
5
7. Print the numbers in the pattern shown 5 ****
for input n. sample output given when 4 ***
n = 5 3 **
2 *
1
8. Print the numbers in the pattern shown 1 * 2 ** 3 *** 4 **** 5 *****
for input n. sample output given when
n = 5
9. Print the numbers in the pattern shown 5 ***** 4 **** 3 *** 2 ** 1 *
for input n. sample output given when
n = 5
10. Print the numbers in the pattern 1 * 5
shown for input n. sample output 2 * 4
given when n = 5 3 * 3
4 * 2
5 * 1
11. Print the numbers in the pattern 1 (0 stars)
shown for input n. sample output 2 ** (2 stars)
given when n = 5 3 ****** (6 stars)
4 ************ (12 stars)
5 ******************** (20 stars)
12. Print the numbers in the pattern 1 * 5 * 5 * 25 * 125
shown for input n. sample output 2 * 4 * 8 * 32 * 256
given when n = 5 3 * 3 * 9 * 27 * 243
4 * 2 * 8 * 16 * 128
5 * 1 * 5 * 05 * 025
13. Print a triangle of numbers for input 01
n. sample output given when n = 6 02 03
04 05 06
07 08 09 10
11 12 13 14 15
16 17 18 19 20 21
14. Print an inverted triangle of numbers 01 02 03 04 05 06
for input n. sample output given when 07 08 09 10 11
n = 6 12 13 14 15
16 17 18
19 20
21
15. Print a triangle of numbers for input 01
n. sample output given when n = 5 02 03
04 05 06
07 08 09 10
11 12 13 14 15
16. Print a spiral matrix of numbers for 01 * 02 * 03 * 04 * 05
input n. sample output given when n = 06 * 07 * 08 * 09 * 10
5 11 * 12 * 13 * 14 * 15
16 * 17 * 18 * 19 * 20
21 * 22 * 23 * 24 * 25
17. Print a spiral matrix of numbers for 01 * 02 * 03 * 04 * 05
input n. sample output given when n = 16 * 17 * 18 * 19 * 06
5 15 * 24 * 25 * 20 * 07
14 * 23 * 22 * 21 * 08
13 * 12 * 11 * 10 * 09
18. Print a spiral matrix of numbers for 01 * 02 * 03 * 04 * 05
input n. sample output given when n = 10 * 09 * 08 * 07 * 06
5 11 * 12 * 13 * 14 * 15
20 * 19 * 18 * 17 * 16
21 * 22 * 23 * 24 * 25
19. Print a spiral matrix of numbers for 01*
input n. sample output given when n = * 09 *
5 * 13 *
* 17 *
* 25
20. Print the difference of two integers n and m without using the minus (-)
operator
21. Print the sum of two integers n and m without using the plus (+) operator
22. Print the product of two integers n and m without using the multiplication
(*) operator
23. Print the division of two integers with numerator n and denominator m without
using the division (/) operator and numerator is a multiple of denominator
24. Given an integer, find the longest Input: 9146826182 Output: 1468
sequence of increasing digits. Sample Input: 924689128 Output: 24689
inputs and outputs given
25. Given an integer, find the longest Input: 9146826182 Output: None
sequence of increasing digits with Input: 9145682618 Output: 456
incremental of 1. Sample inputs and
outputs given
26. Find a given digit n in a given Input: n = 4, m = 124475577
integer m Output: 4
27. Print digits in a given integer as Input: 124475577
shown in the sample. The length of Output:
the number does not exceed 10 digits. first digit : 1
second digit : 2
third digit : 4
fourth digit : 4
and so on
28. Print frequency of digits in a given Input: 124475577
integer. The length of the number Output:
does not exceed 10 digits. 1 : 1 (first digit)
2 : 1 (second digit)
4 : 2 (third, fourth digits)
5 : 2 (sixth, seventh digits)
7 : 3 (fifth, eighth, ninth digits)
29. For input of odd integer n, print a * * * * *
half-rhombus shaped pattern using * * * *
'*', example shown for n = 5 * * *
* *
*
30. For input of odd integer n, print a *
half-rhombus shaped pattern using * *
'*', example shown for n = 7. Also * * *
print the mirror image of the output. * * * *
* * *
* *
*
31. For input of integer n, print a *
rhombus shaped pattern using '*', * *
example shown for n = 4 * * *
* * * *
* * *
* *
*
32. Print the sums of all even and odd Input: 12345678
digits of an integer Output:
Sum of all odd digits: 16
Sum of all even digits: 20
33. Print the sum digits of an integer m Input: m = 1132548 condition = odd
for a given condition Output: 10
Input: m = 1132548 condition = even
Output: 14
34. Replace each digit of a number with Input: 123
its word form Output: one two three
35. Print a 4-digit number in words form. Input: 2345
Output: two thousand three hundred
forty five
36. For input n, print number of ways to Input: 4
form sum using 1s and 2s. Order Output: 5
matters. 1 1 1 1
1 1 2
1 2 1
2 1 1
2 2
37. Check if a number is a palindrome Input: 121 Output: 121 is a
without converting to string. Palindrome
Input: 122 Output: 121 is not a
Palindrome
38. Print a hollow square pattern of '*' Input: n = 4
for a given size n. Output:
* * * *
* *
* *
* * * *
39. Print a full square pattern of '*' Input: n = 4
for a given size n Output:
* * * *
* * * *
* * * *
* * * *
40. Write a program to print any alphabet Input: A
using * Output:
*
* *
* *
*******
* *
41. Print a diamond pattern of numbers Input: 5 Input: 7
for a given odd number n Output: Output:
1 1
1 2 1 1 2 1
1 2 3 2 1 1 2 3 2 1
1 2 1 1 2 3 4 3 2 1
1 1 2 3 2 1
1 2 1
1
42. Write a program to reverse a number n Input: 1234 Output: 4321
43. Write a program to add all even Input: 1235
digits and multiply all odd digits of Output:
a given number n Sum of odd digits: 4
Sum of even digits: 7
44. Write a program to add all digits Input: 12350
that are even and multiply all odd Output:
digits of a given number n Sum of digits that are even: 2
Product of digits that are odd: 15
45. Write a program to display Input: n = 10 m = 20
multiplication table for a given Output:
number n upto the multiplier m 10 x 1 = 10
10 x 2 = 20
..
10 x 20 = 200
46. Write a program to accept N numbers Input: N = 10
and find the largest and smallest of n1 = 100 ; n2 = 202334; n3 = 3; ….
them n10 = 6451
Output:
Smallest number is: 3
Largest number is: 202334
47. Write a program to search a digit n Input: N = 500; n = 0
in a given number N Output:
0 occurs 2 times
48. Write a program find the nth digit of Input: N = 50023; n = 4
a number N Output:
4th digit is 2
49. Write a program that accepts 2 co-ordinates (x, y) and (x’, y’) of a
rectangle of size n(length) x m(width) and finds the distance between them.
50. Refer to Fresher Profiles – Student agreement and write a program to
calculate the placement assistance fee a student would pay based on the CTC
and placement drive type.
51. A cricket batter is dismissed after facing n balls and scores m runs by
hitting x fours, y sixes, z twos, and w ones. Write a program to calculate
the strike rate, percentage contribution of each run type, and analyze data
for p players to determine:
• The player with the highest strike rate
• The player who scored maximum runs
• The player who scored minimum runs
• The player who hit the most sixes
• The player who hit the most fours
52. Write a program to generate a receipt based on the items sold in a pizza
shop. The format of the receipt is as below
----------------------------------------------------------------
Sr. No. Item Name Qty UoM Rate Sub-Total
-------+------------------+------+------+-----------+-----------
1. + Cheesecake + 1.45 + Kg + 100.00 + 145.00
2. + Farmhouse Pizza + 3 + M + 1243.20 + 3729.80
3.
..
n. + Garlic Bread + 2 + Num + 149.99 + 299.98
-------+------------------+------+------+-----------+-----------
TOTAL NNNNNN.NN
----------------------------------------------------------------
53. Write a program to print the area of a geometric shape such as a triangle,
square, or circle etc. The program should prompt the user to specify the type
of shape and then request the necessary dimensions to find its area.
54. Write a program to find the length of a floating-point number. For eg.,
1234.567 should result in length = 4,3