You are on page 1of 4

Python programs on Loops

1) Write a Python program to find those numbers which are divisible by 8 and
multiple of 5, between 100 and 600 (both included).
2) Write a Python program to count the number of even and odd numbers
from a series of numbers.
3) Write a Python program which accepts a sequence of comma separated 4
digit binary numbers as its input and print the numbers that are divisible by
4 in a comma separated sequence
Sample Data : 0110,0011,1010,1001,1100
Expected Output : 1100

Python programs on Operators


1) Write a program to compute distance between two points taking input from the
user (Pythagorean Theorem)
2) Write a Python program to add two positive integers without using the '+'
operator. Note: Use bit wise operations to add two numbers.
3) Write a Python program to find the number of notes (Sample of notes: 10, 20,
50, 100, 200 and 500 ) against an given amount. Range - Number of notes(n)
: n (1 = n = 1000000).

Python programs on Tuples


1) Write a Program to access element using tuple indexing, consider a tuple
having 6 elements will have index from 0 to 5. Trying to access an element
other that (6, 7,...) will raise an IndexError.
2) Write a program to access a range of items in a tuple by using the slicing
operator - colon ":"
3) Write a program to find number whose sum of digits is largest using key
function

Python programs on Lists


1) Consider a list (sample_list = []). You can perform the following commands:
 Read 5 integer elements append in list
 Insert 5 at 0th position
 print: Print the list.
 Delete the first occurrence of even integer .
 print: Print the list.
 Insert 27 at the end of the list
 print: Print the list.
 Sort the list.
 print: Print the list.
 Pop the last element from the list.
 print: Print the list.
 Reverse the list.
 print: Print the list.
2) Given the participants' score sheet for your University Sports Day, you are required to
find the runner-up score. You are given scores. Store them in a list and find the score of the
runner-up.

Sample Input

5
23665
Sample Output

5
3) Given the names and grades for each student in a Physics class of students, store them in
a nested list and print the name(s) of any student(s) having the second lowest grade.
Note: If there are multiple students with the same grade, order their names alphabetically and
print each name on a new line.

Sample Input 0

5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39
Sample Output 0

Berry
Harry

Python programs on Dictionary

1) You have a record of N students. Each record contains the student's name, and their
percent marks in Maths, Physics and Chemistry. The marks can be floating values. The
user enters some integer N followed by the names and marks for N students. You are
required to save the record in a dictionary data type. The user then enters a student's
name. Output the average percentage marks obtained by that student, correct to two
decimal places.

Sample input:

3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika
Sample output:

56.00

2) Python program to find First two minimum salaries in an Organization

Write a program to read emp name and salary in to a dictionary and print first two minimum
salaries of an organization.

Sample input:

Ravi 25000

Hari 28000

Raghu 22000

Priya 30000

Shruthi 21000

Sample Output:

Shruthi 21000

Raghu 22000

3) Sum list of dictionaries with same key

Sample input:[{'a':5, 'b':10, 'c':90},{'a':45, 'b':78},{'a':90, 'c':10}]


Sample output: {‘b’: 88, ‘a’: 140, ‘c’: 100}

Python programs on Strings


1) Write a python program to read mobile number in to a string S check whether the S is
having only digits with 10 digits.
Sample input: 9848123456
Sample Output: Yes! It is a valid mobile number
Sample input: 98481
Sample Output: No! It is not a valid mobile number
Sample input: 9848i23456
Sample Output: No! It is not a valid mobile number
2) You are asked to ensure that the first and last names of people begin with a capital letter
in their passports. For example, mark zuckerberg should be capitalised correctly as Mark
Zuckerberg

Sample Input

mark zuckerberg

Sample Output

Mark Zuckerberg

3) In this challenge, the user enters a string and a substring. You have to print the number of

times that the substring occurs in the given string. String traversal will take place from

left to right, not from right to left.

NOTE: String letters are case-sensitive.

Sample Input

ABCDCDC
CDC
Sample Output

You might also like