SIMATS ENGINEERING
SAVEETHA INSTITUTE OF MEDICAL AND TECHNICAL SCIENCES
CHENNAI-602105
CSA08 – PYTHON PROGRAMMING
LEVEL WISE QUESTIONS(Sample)
[Link] QUESTIONS
LEVEL 1 QUESTIONS
1 Read the number until -1 is encounter. find the avg of positive numbers and
negative numbers entered by user
Sample Input:
Enter -1 to exit, enter the numbers 7,-2,9,-8,-6,-4,10,-1
Output: avg negative number is -5, avg positive number is 8
2 Write a python program to find the square, cube of the given decimal number.
Sample Input:
Given Number: 0.6
Output:
Square Number: 0.36
Cube Number:0.216
3 Write a python program to print the following pattern.
Sample Input:
Enter the Character to be printed:+
Number of rows.: 5
Output:
+
++
+++
++++
+++++
4 Python Program to Display the Multiplication Table
Sample Input:
A=7
B=5
Output:
7x1=7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
5 Write a program to find whether it is leap year or not?
Sample Input: 2000
Output: Leap Year
6 Write a program to find out the duplicate array
Sample Input: array={1,2,3,4,1}
Output: duplicate array={1,2,3,4}
7 Check whether the number is positive or negative
Sample Input:23
Output: positive
8 Write a python program to find the average of mean median mode
Sample Input: [12,45,83,52]/4
Output: utput:48
9 Write a python program to store the arrays in non-increasing order
Sample Input:[1,8,3,4,0]
Output:[8,4,3,1,0]
10 Write a Python Program to Intersecting an elements
Sample Input:
(2,3,4,5)
(3,4,8,6)
Output:
(3,4)
LEVEL 2 QUESTIONS
1 To count all the prime numbers and composite numbers
Sample input: 4,54,29,71,59,98,23
Output: composite numbers=3
Prime numbers = 5
2 Sum of daigonal matrix
Sample input: [1 2 3 4 5 6 7 8 9]
Output: diagonal elements are 1,5,9
Sum of diagonal elements=15
3 Perfect number or not
Sample Input: 6
Output: it is a perfect number
4 Write a program in Python to read the elements of a one-dimensional array,
compare the elements and find which are the largest two elements in a given
array.
Sample Input:
1234567
Output:
Largest two elements : 6 & 7
5 Find the Mth maximum number and Nth minimum number in an array and
find the sum and difference of it.
Sample Input:
Array of elements = {14, 16, 87, 36, 25, 89, 34}
M=1
N=3
Output:
1st Maximum Number = 89
3rd Minimum Number = 25
Sum = 114
Difference = 64
6 Find GCD and LCM in Python
Sample Input & Output:
LCM of 15 and 20 is 60
The gcd of 60 and 48 is : 12
7 Write a Python program to display customer name mobile number and cost of
the [Link] the discount and find the total amount to be paid.
8 Write a Python program to find largest 2nd maximum in array
Sample Input:
a={1,6,4,2}
Output:4
9 You are give with an array which contains integer element. Sort the elements
in non-increasing order and print the middle element of the array.
Sample Input:
arr = {90,-90,80,66,78,10}
Output:
{-90,10,66,78,80,90}
Mid-element:66
10 Write a python program to print multiplication of 3 matrices.
First matrix elements:
111
222
333
Second matrix elements
111
222
3 3 3 ki
Third matrix elements
111
222
333
multiplication of the matrix:
36 36 36
72 72 72
108 108 108
LEVEL 3 Questions
1 Write a Python program to display most and least significant digit of a
number.
Sample Input :
1267899
Output:
LSB : 1 & MSB : 9
2 Given a positive integer N. The task is to find 12 + 22 + 32 + ….. + N2.
Sample Input: n = 4
Output: 30
3 Check whether a number is Tech Number or not
Sample Input: n = 2025
Output: True
4 Write a Python program to convert decimal to binary number
Sample Input : 7
Output :111
5 Write a Python Program to print all Possible Combinations from the three
Digits
Input: [1, 2, 3]
Output:
123
132
213
231
312
321
6 In a daily share trading a buyer buys shares in the morning and sells them on
the same day if the trader is allows to make at most 2 transactions in a day
where as the 2nd transaction can only start after the 1ts one is completed(buy-
>sell->buy->sell).given stock price through out the day. Find ot the maximum
profit that a share trader could have made
Sample Input:
Prices=[7,1,5,3,6,4]
Output:7
7 Suppose an array of length n sorted in ascending order is rotated in between 1
and n times
Sample Input:
nums =[0,1,4,4,6,7]
Output:
[4,5,6,7,0,14] it was rotated 4 times
[0,1,4,4,5,6,7] if it was rotated 7 times
Notice that rotating an array [a[0], a[1],a[2],…a[n-1]] 1 time result in the array
[a[n-1],a[0],a[1],a[2],…,a[n-2]].
8 Given an array of integers num sorted in non-decreasing order, find the
starting and ending position of given target value if target is not found in the
array, return[-1,-1]
Sample Input:
nums =[5,7,7,8,8,10]
Target=8
Output: [3,4]
9 Given string num representing a non-negative integer num, and an integer k,
return the smallest possible integer after removing k digits from num.
Example 1:
Sample Input: num = "1432219", k = 3
Output: "1219"
Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219
which is the smallest.
Example 2:
Sample Input: num = "10200388", k = 1
Output: "200388"
10 Write a Python program to print a matrix in spiral order. Given an m x n
matrix, return all elements of the matrix in spiral order, starting from the top-
left and moving inwards.
Spiral Order Definition:
In spiral order traversal, you visit all elements of the matrix starting from the
top-left corner and proceeding in a circular, clockwise direction, layer by
layer.
Sample Input:
1 2 3
4 5 6
7 8 9
Output:
[1, 2, 3, 6, 9, 8, 7, 4, 5]