Programming and Problem Solving through Python (M3-R5.1)
Prepare, Train & Test Yourself
Python Programs
Question - 1
Write a Python function that takes a string as parameter and returns a string with
every successive repetitive character replaced by & e.g. Parameter may become
Par&met&r.
Question - 2
Write a function in Python to print all prime numbers between 500 and 1500.
Question - 3
Write a program in Python to reverse the digits of a given number (the number 69876 should be
returned as 67896).
Question - 4
Write a program in Python that opens two files and copies content of the first file in the second
file. It should have an exception to handle non existing file in case of reading first file.
Question - 5
Write a Python function to find the sum of all numbers between 100 and 500 which
are divisible by 2.
Question - 6
Write a program in Python to convert a given decimal number to its octal equivalent and vice
versa. Prompt user with proper input and output messages.
Question - 7
Write a program in Python to sort an array of number. It should (a) display the greatest and
smallest numbers of the array (b) delete a given element from an array and then shift rest of
the elements in the array towards left.
Question - 8
Write a Python function to get two matrices and multiply them. Make sure that number
of columns of first matrix = number of rows of second.
Question - 9
Write a Python function that takes an integer value and returns the number with its digits reversed.
Question - 10
Write a Python function which takes list of integers as input and finds:
(a) The largest positive number in the list
(b) The smallest negative number in the list
(c) Sum of all positive numbers in the list
Question - 11
Write a program in Python to print total numbers of odd integers and their sum in
an array that contains 15 elements.
Question - 12
Write a Python program to print all the prime numbers in the given range. an
Interval. A prime number is a natural number greater than 1 that has no
positive divisors other than 1 and itself.
Question - 13
Write a program in Python that counts the number of occurrences of a particular character
in a line of text. Print the character and its number of occurrences.
Question - 14
Write a program in Python to get two arrays and multiply the members term by term
and then display the output.
Question - 15
Write a Python Program that Convert decimal number into binary number.
eg. The number 70 in decimal is expressed as 1000110 in binary.
Question - 16
Write a program in Python to get a count and display of the Fibonacci series as
follows:
Enter Count: 10
Output:-
Series is : 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
Question - 17
Write a Python program that takes list of numbers as input from the user and
produces a cumulative list where each element in the list at any position n is
sum of all elements at positions upto n-1.
Question - 17
Write a Python program to multiply two numbers by repeated addition e.g.
6*7 = 6+6+6+6+6+6+6
Question - 18
Write a program in Python to find the sum of all prime numbers between 100 and 500.
Question - 19
Write a program in Python to get two matrices and multiply them. Make sure that number of
columns of first matrix = number of rows of second.
Question - 20
Write a Python function that takes a string as parameter and returns a string with every
successive repetitive character replaced by ? e.g. school may become scho?l.