0% found this document useful (0 votes)
101 views

P3 Python Question Bank

This document contains 34 questions related to Python programming. The questions cover a variety of topics like lists, strings, functions, prime numbers, Fibonacci series, Armstrong numbers, binary and decimal conversions, bank transactions, palindrome checking and more. The questions range from easy to medium difficulty levels.

Uploaded by

shashionline123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

P3 Python Question Bank

This document contains 34 questions related to Python programming. The questions cover a variety of topics like lists, strings, functions, prime numbers, Fibonacci series, Armstrong numbers, binary and decimal conversions, bank transactions, palindrome checking and more. The questions range from easy to medium difficulty levels.

Uploaded by

shashionline123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

P3 Python Question Bank

Difficulty
Q.No. Question Marks
Level
Even Numbers

1 You are given a list of integers. Write a python program to print only the unique even numbers present in Easy 20
the list. If there are no even numbers, then print "Nil". Arrange the output in ascending order.
Odd Factors
2 Easy 20
Write a Python program to print the odd factors of a number. Arrange the output in ascending order.
Unique Numbers
3 Write a Python program that takes a list of integers, removes duplicates and prints only the unique Easy 20
numbers present in the given list. Skip the numbers divisible by 3. Arrange the output in ascending order.
Non Repeating Numbers

4 Write a Python program that takes a list of numbers and prints only those numbers which are not repeated. Easy 20
If there are no non-repeated numbers, print "None"
Form a New Number
Write a Python program which takes an integer as input and forms a new number which has the least
5 Easy 20
significant digit of the original number in its one's place and total number of digits of the original number
in ten's place.
Reverse the List and Find the Sum
6 Write a Python program to take a list and reverse the list and make a new list whose elements are equal Easy 20
to the sum of corresponding elements of the original list and the reversed list.
LCM Function
7 Easy 20
Write a Python function "LCM()" which takes two numbers and returns their LCM.
GCD Function
8 Easy 20
Write a Python function "GCD()" which takes two numbers and returns their GCD.
Prime Number Function

9 Write a Python function "Fun_Prime()" that takes a number and returns True if it is prime and returns Easy 20
False otherwise.
Prime Numbers in an Interval
10 Medium 30
Write a Python program to generate prime numbers within a given interval.
Next 10 Prime Numbers
11 Medium 30
Write a Python program to generate next 10 prime numbers starting from a given number.
Leap Year Function
Write a Python function "is_leap()" that takes a year as input and returns True if it is a leap year and

12 returns False otherwise. Medium 30


A leap year is divisible by 4 except for century years. A century year is a leap year only if it is divisible
by 400.
Leap Years in an Interval
13 Medium 30
Write a Python program to generate leap years in an interval.
Next 10 Leap Years
14 Medium 30
Write a Python program to generate next 10 leap years starting from a given year.
Factorial Function
15 Easy 20
Write a Python function "fun_fact()" to find the factorial of a given number.
Fibonacci Series Function

16 Write a Python function "Fun_Fib()" that takes an integer as input and generates a Fibonacci series of that Easy 20
length.
Fibonacci Series Member

17 Write a Python function "Is_Fib()" which takes a number and returns True if the number is a member of Medium 30
Fibonacci series. Otherwise, return False.
Fibonacci Series in an Interval

18 Write a Python program which takes a lower limit and an upper limit and prints the Fibonacci numbers Medium 30
in that interval.
Sum of Squares of First n Natural Numbers
19 Easy 20
Write a Python program to find the sum of square of first n natural numbers.
Armstrong Number Function
Write a Python function "Is_Armstrong()" to check whether a given number is Armstrong number or not.
Print True if the number is Armstrong number. Otherwise print False.
20 Easy 20
Note : Armstrong number is a number which is equal to sum of its digits raised to the number of digits
present in that number.
For Ex. consider 153. It has 3 digits. 1^3+5^3+3^3=153. Hence 153 is an Armstrong number.
Rule Based Product
Write a python program to find the product of a list of numbers based on the following rules.
If 5 is not present in the list, display the product of all the numbers.
21 Medium 30
If one of the integers is 5, display the product of numbers to the right of 5 excluding 5 and any subsequent
5's.
If there are no numbers to the right of 5, display -1.
Perfect Square

22 Write a Python function 'Is_Square()' to check whether the given integer is a perfect square or not. Return Easy 20
True if yes, otherwise return False.
Perfect Square in an Interval

23 Write a Python program to generate perfect squares within a given interval. Print "Nil" idf there are no Medium 30
perfect squares within the given interval.
Next 10 Perfect Squares
24 Medium 30
Write a Python program to generate next 10 perfect squares starting from a given integer.
Spy Number
Write a Python function 'Spy()' to check whether a given number is Spy number or not. Print True if the
25 Medium 30
number is a Spy number. Otherwise print False.
A number is said to be a Spy number if the sum of all the digits is equal to the product of all digits.
Decimal to Binary
26 Medium 30
Write a Python program to convert the given decimal number into an equivalent binary number.
Binary to Decimal
27 Easy 20
Write a Python program to convert the given binary number to its decimal equivalent.
[Note : Binary number is input as a string.]

Bank Transaction
Write a python program to compute the net amount of a bank account based on a transaction log.
Input Description: The transaction log format is as follows.

28 First line : Integer n, which specifies the number of transactions Medium 30


Second line onwards: A character and an integer separated by space.
Character D indicates deposit(D) and character W indicates withdrawal (W). The integer part indicates
the amount.
Sum of Consecutive Primes
Some prime numbers are equal to the sum of other consecutive prime numbers.
29 Medium 30
For example 5 = 2 + 3, 17 = 2 + 3 + 5 + 7, 41 = 2 + 3 + 5 + 7 + 11 + 13.
Write a python program to print the prime numbers that satisfy this property up to a given number.
Words Longer Than n

30 Write a Python program that takes a list of words and prints only the words having more than 5 letters. If Easy 20
there are no such words, print - Nil
Names starting with "Rr" and ending with "Hh"

31 You are given a list of unique names. Write a Python program to print the names that start with "R" or "r" Easy 20
and end with "H" or "h". If there are no such names, print -1.
Palidrome

32 You are given a list of words. Write a Python program to print only the palindromes present in the list. If Easy 20
there are no palindromes in the given list, then print "Nil".
Likes Dislikes
Two people made a list of movies they like and dislike. Write a Python program to find the number of

33 movies they both like and the number of movies they both dislike. Easy 20
Input Description : Input1 and Input2 are strings containing 1s and 0s. 1s represent likes and 0s represent
dislikes.
Remove Space and Find Length

34 Given a string, write a Python program to remove all the spaces and find the length. Also, output whether Easy 20
the length is even or odd.
Common Words

35 You are given two sentences. Write a Python program to print only the common words of the two Easy 20
sentences. If there are no common words, then print "Nil".
Alphabetical Chars, Digits, Spaces, Special Chars

36 You are given a string. Write a Python program to print the number of alphabetical characters, digits, Easy 20
spaces, special characters.
Vowels and Consonants

37 You are given a string. Write a Python program to find the number of vowels and consonants present in Easy 20
the string.
Uppercase, Lowercase
38 Easy 20
You are given a string. Write a Python program to print the number of uppercase and lowercase letters.
Remove Vowels from a String

39 You are given a list of strings. Write a Python program to remove vowels from every string and print the Easy 20
new list.
Word With Highest Number of Vowels
40 You are given a list of words. Write a Python program to print the word with highest number of vowels Medium 30
in it. If two words have equal number of vowels, then select the word which appears first in the given list.
Remove Repeated Words
41 Easy 20
You are given a sentence. Write a Python program to remove the repeated words of length greater than 5.
Remove Non Repeated Words

42 You are given a sentence. Write a Python program to remove the non-repeated words of length greater Easy 20
than 5.
Valid Password
You are given a list of strings. Write a Python program to print only the valid passwords among them. A
valid password contains
 at least 2 lower case letters

43  at least 2 upper case letters Medium 30


 at least one digit
 no space
 at least one special character from !@#$%^&*
Minimum length of password is 8 and maximum length is 16.
Anagrams
You are given a string. Write a Python program to print only the anagrams present in the string.
44 Medium 30
Anagram means words containing same letters.
For Ex. listen and silent are anagrams.
Heterograms
Write a Python program to check whether a given string is Heterogramor not. Return True if the given

45 string is a Heterogram. Otherwise, return False. Easy 20


A heterogram is a word, phrase, or sentence in which no letter of the alphabet occurs more than once.
For ex. ‘the big dwarf only jumps’
Shadow Sentence

46 Write a Python function 'shadow()' which takes two sentences as input and returns True if they are shadow Medium 30
sentences and False if they are not.
Voting Machine
Voting was held in a class to elect class representative. A list of names students voted is given to you.

47 Write a Python program to find who got the maximum number of votes. If two students got equal number Medium 30
of votes, then elect the one whose name comes first in alphabetical order. Also display the number of
votes the winner got.
Vehicle Parking Space Allotment
You are given several strings containing 0s and 1s.
0 indicates an empty parking space and 1 indicates an occupied parking space.
Imagine a new vehicle enters the parking lot.

48 Write a Python program to allot parking space in the row which contains maximum number of empty Medium 30
slots.
In case two rows have equal number of empty slots, then the program should choose the row which
appears first in the list.
In case there are no empty space for parking, then print "None".
Input Description : First integer represents the number of rows. Then the strings are entered one below
the other.
Wonderful String
You are given a list of strings. Write a Python program to print only the wonderful strings.
49 Easy 20
A wonderful string is a string which is made up of exactly three different letters.
Print "None" if there are no wonderful strings in the given list.
Car Engine Number
A car company numbers the engines based on the car’s number plate.

50 The engine number is the sum of all the integers present on the car’s number plate. Easy 20
Develop a Python program which takes input in the form of a string (Car Number) and gives back the
car’s engine number in the form of an integer.
Name, Company from Email ID
You are given a list of email IDs. Write a Python program to extract name of the employee and the name

51 of the company. Easy 20


Input Description : First integer gives the number of elements. Then the elements are are entered one
below the other.
Parentheses Matching

52 You are given a list of strings. Write a Python program to print the strings in which parenthesis are Medium 30
matched.

53 Histogram (V1) Medium 30


You are given a list of integers. Write a Python program to output a dictionary with the numbers as keys
and their frequency of occurance as values. Arrange the dictionary elements in the ascending order of
their keys.
Roman to Decimal

54 Write a Python program to convert Roman number into equivalent decimal number. Medium 30
(Roman Numbers : I->1, V->5, X->10, L->50, C->100, D->500, M->1000)
Largest Even Number
You are given a string containing letters, digits and special characters. Write a Python program to find the
55 Medium 30
largest even number which can be formed from the available digits. If even number cannot be formed,
then print 'Nil'.
String Similarity
You are given 2 strings. Write a Python program to print the similarity value of the two.
56 Easy 20
Similarity value=(2*Number of same letters in same position)/Total number of letters.
Print the value for 3 decimal places.
Starts With Hello, Ends With a Digit
You are given a list of strings. Write a Python program to print only those strings which start with "Hello"
57 Easy 20
and end with a digit.
Input Description : First entry tells the number of strings. Then the strings are entered one below the other.
Valid USN
You are given a list of strings. Write a Python program to output only valid USNs from the given list. If
58 Medium 30
there are no valid USNs, then print 'Nil'.
For Ex. 1CR22EC285 is a valid USN.
A valid USN contains exactly 10 characters out of them 1st character is a digit, next 2 characters are
alphabetical characters, then two digits, then 2 alphabetical characters, then 3 digits.
Input Description : First integer is the number of inputs. Then the list elements are entered one below the
other.
Valid PAN
You are given a list of strings. Write a Python program to print only the valid PAN (Permanent Account
Number) from the given list. If there is no valid PAN, print "Nil".

59 For Ex. BDDQG6697D is a valid PAN. Medium 30


A PAN contains 5 letters follwed by 4 digits followed by 1 letter.
Input Description : The first entry tells the number of strings. Then the strings are entered one below the
other.
Valid Vehicle Number
You are given a list of strings. Write a Python program to print only the valid vehicle numbers from the
list. If there are no valid vehicle numbers, print 'Nil'

60 For. Ex. KA63KN2024 is a valid vehicle number. Medium 30


A valid vehicle number contains 2 letters follwed by 2 digits followed by two letters and then 4 digits.
Input Description : First input tells the number of strings. Then the list elements are entered one below
the other.
Valid Phone Number
You are given a sentence. Write a Python program to extract the valid phone numbers present in the
61 Medium 30
sentence. If there is no valid phone number, print 'Nil'.
For Ex. 080-2847-4463 is a valid phone number.
Valid URL
62 You are given a list of strings. Write a Python program to print only the valid URLs from the given list. Medium 30
If there is no valid URL, print "Nil".
Valid Mobile Number
You are given a sentence. Write a Python program to extract the valid mobile numbers present in the
63 Medium 30
sentence. If there is no valid phone number, print 'Nil'.
For Ex. +91-9078912345 is a valid mobile number.
Valid Email ID

64 You are given a sentence. Write a Python program to print valid email IDs present in the sentence. If there Medium 30
are no email IDs, then print "Nil".
Valid Date Format
Write a Python program to take dates as string input and convert dates of yyyy-mm-dd format to dd-mm-
65 Easy 20
yyyy format.
If the date is in dd-mm-yyyy format do not change it.
Valid IP Address
You are given a list of strings. Write a Python program to print only the valid IP addresses from the list.

66 A valid IP address contains four numbers ranging from 0 to 255 separated by dot. Medium 30
A number cannot start with 0 unless 0 is the only digit in that number.
If there are no valid IP addresses in the list, print "Nil".

67 Fill With Stars Easy 20


You are given a sentence. Write a Python program to extract only the odd length words. If the length of
those words is less than 10, then pad them with * in the right and make their length as 10. If the odd length
word has greater than 10 letters, print the word as it is.
Pythagorean Triplets
You are given a list of triplets. Write a Python program to print only the Pythagorean Triplets present in
68 Easy 20
the list. Print "Nil" if there is no Pythagorean Triplet.
For Ex. 3,5,4 is a Pythagorean Triplet. Because, 3^2 + 4^2 = 5^2
Linear Search
You are given a list of integers. Write a Python function to search for the given element in the list using
69 Easy 20
Linear Search method. If the element is present in the list, print the index of the element. Otherwise print
"Not Found".
Binary Search

70 You are given a list of integers sorted in ascending order. Write a Python function to search for a given Easy 20
element in the list using Binary Search method.
Bubble Sort

71 You are given a list of integers separated by space in a single line. Write a Python function 'Bubble_Sort()' Easy 20
to sort the list in ascending order.
Class Circle
Write a Python program to create a class representing a circle. Include methods to calculate its area and
72 Medium 30
circumference.
Take radius of the circle as input from the user.
Class Complex
Write a Python program to create a class called 'Complex'. Each Complex object should have real part
and imaginary part. Include method to find the magnitude and phase of the complex number.

73 [ Hint 1 : Use round(x,4) function to limit the decimal values to 4 positions.] Medium 30
[ Hint 2 : Import math module and use math.atan2(imaginary_part,real_part) function to find the phase of
the complex number.]
[ Hint 3 : Magnitude of a complex number is equal to square root of (real_part^2 + imaginary_part^2) ]
Class Complex Addition

74 Write a Python program to create a class called 'Complex'. Each Complex object should have real part Medium 30
and imaginary part. Include method to add two complex numbers.
Class Student
Write a Python program to create a class called 'Student'. Include methods to find the percentage and
SGPA of the student. Consider marks scored by the student in three subjects out of 50.
75 Medium 30
SGPA=(Percentage/10)+0.75
If the calculated SGPA is greater than 10, consider SGPA as 10.0
[ Hint : Use round(x,2) function to limit the decimal values to 2 positions]
Class Employee
Write a Python program to create a class called 'Employee'. Include methods to calculate monthly salary
to be paid and update leaves remaining. Take actual salary and number of leaves taken as input from the
76 Medium 30
user.
Monthly Salary to be Paid = 90% of Actual Salary
10% of salary is deducted as tax.
Leaves Remaining = 12 - Number of Leaves Taken

Class Rectangle
Write a Python program to create a class called 'Rectangle'. Include methods to calculate area of the
77 Medium 30
rectangle and the length of the diagonal. Take the length of the sides as input from the user.
[ Hint : Use round(x,2) function to limit the decimal values to 2 positions]

You might also like