0% found this document useful (0 votes)
26 views15 pages

Python Practical Question Bank - 2

The document contains a list of 60 Python programming tasks that cover various concepts such as file handling, recursion, data structures, and mathematical operations. Each task includes a brief description of the required functionality, such as checking divisibility, calculating factorials, and manipulating strings and lists. The tasks are designed to help learners practice and enhance their Python programming skills.

Uploaded by

Yogesh Gawai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views15 pages

Python Practical Question Bank - 2

The document contains a list of 60 Python programming tasks that cover various concepts such as file handling, recursion, data structures, and mathematical operations. Each task includes a brief description of the required functionality, such as checking divisibility, calculating factorials, and manipulating strings and lists. The tasks are designed to help learners practice and enhance their Python programming skills.

Uploaded by

Yogesh Gawai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Python Programs

1. Write a program to check whether input number is divisible by 3 or 5 or both.

2. Write a program to read and display first and last n lines from a file.

3. Write a program which finds sum of digits of a number.

4. Write python program to find factorial of numbers using recursion.

5. Write a program to calculate the factorial of a number.


6. Write python program to find GCD of numbers using recursion.

7. Write a program which finds all factors of a number.

8. Write python program using an anonymous function to find area of circle,


circumference of circle.

9. Write a program to accept 5 numbers and calculate its Mean value.


10.Write python program which provides a hint to the user so that he can figure out the
correct alphabet. The program will ask the user to enter an alphabet until they guess a
stored alphabet correctly.

11.Write a program which reverses a string and displays both original and reversed string.

OR

s1=input("Enter a string: ")


print("Enter a original: ",s1)
s2=s1[::-1]
print("Reverse string: ",s2)

12.Write python program to find factorial of numbers using recursion.

13.Write a program which accepts 10 integers and prints "DUPLICATES" if any of the
values entered are duplicates otherwise prints "ALL UNIQUE".
14.Write a program to read a string from the user and append it into a file.

OR
str1=input("Enter one string:")
f=open('abc.txt','a')
f.write(str1)
f.close()

15.Write a program which prints fibonacci series of a number.

16.Write a program which reads a text file and counts the number of times a certain letter
appears in the text file.
17.Write a program which accepts an integer value 'n' and prints all prime numbers
till 'n'.

18.Write python program using an anonymous function to find area of circle,


circumference of circle.

19.Write a program to count the number of characters in a string.

OR
str1=input("please enter your own string:")
total=0
for i in str1:
if i.isalpha():
total=total+1
print("Total number of character in this string=",total)

20.Write a Python program to check if a given key already exists in a dictionary. If key
exists replace with another key/value pair.
21.Write a program to find the length of a set.

22.Write python program to accept and print string in reverse order using recursion.

23.Write a program which finds sum of digits of a number.

24.Write a python program to accept NxN matrix and display the same.

25.Write a program to reverse a tuple.

26.Read a text file and print all the numbers present in the text file. Also print the size of
the file.
fname = input("Enter file name: ")
with open(fname, 'r') as f:
for line in f:
words = line.split()
for i in words:
for letter in i:
if(letter.isdigit()):
print(letter)

27.Write a program to find the repeated items of a tuple.

28.Write a Python program to accept n numbers in list and find maximum and minimum
from list.

29.Write a program to create a list of tuples with the first element as the number and
second element as the square of the number.

OR
l_range=int(input("Enter the lower range:"))
u_range=int(input("Enter the upper range:"))
a=[(x,x**2) for x in range(l_range,u_range+1)]
print(a)

30.Write a Python script to generate and print a dictionary that contains a number
(between 1 and n) in the form (x, x*x).
Sample Dictionary (n = 5)
Expected Output : {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}

31.Write a program to convert a tuple to a string.

32.Write a Python program to accept n numbers in list and remove duplicates from a list.

33.Write a program which checks whether an element exists within a tuple.

34.Write a Python program to accept n numbers in list and find sum and average of
numbers in list.
OR
list=[]
n=int(input("Enter number of element:"))
for i in range (0,n):
ele=int(input("Enter elements:"))
list.append(ele)
count=sum(list)
avg=count/len(list)

print("Sum is:",count)
print("avg is:",avg)

35.Write a program to create set difference and a symmetric difference.

36.Write a Python program to accept n elements in a set and find the length of a set,
maximum, minimum value and the sum of values in a set.

37.Write a program to accept 10 numbers and find its median .

38.Write a Python program to create a tuple of n numbers and print maximum, minimum,
and sum of elements in a tuple.
n = int(input("Enter the number of integers you'd like to enter: "))

print()
l = list()

for i in range(n):

x = int(input("Enter the integer: "))

l.append(x)

print()

print()

n1 = tuple(l)

print(n1, "is your given tuple.")

print()

print(max(n1), "is the MAXIMUM value in the tuple.")

print()

print(min(n1), "is the MINIMUM value in the tuple.")

print()

print(sum(n1), "is the SUM of the values in the tuple.")

print()

39.Write a program to accept 10 numbers, display the sum of odd numbers and sum of
even numbers.
40.Write a program to create tuple of n numbers, print the first half values of tuple in one
line and the last half values of tuple on next line.

41.Write a program to accept a number 'n', and display the following pattern (Floyd's
triangle)n=3
1
23
456

42.Write a Python program to perform operation on sets which includes union of two sets,
an intersection of sets, set difference and a symmetric difference.

43.Write a program to accept 10 numbers and find its Mode.

44.Write a Python program to accept two lists and merge the two lists into list of tuple.
45.Write a program to accept a number and display its first ten multiples.

46.Write a Python program to accept a string and from a given string where all
occurrences of its first character have been changed to '$', except the first char itself.

47.Write a program to display the following pattern.


1 2 3 4
1 2 3
1 2
1

48.Write a Python program to count frequency of each character in a given string using
user defined function.
49.Write a program to create list of tuples with the first element as the number and second
element as the cube of the number.

50.Write a Python program to count the occurrences of given word in sentence. Accept
sentence and word from user.

51.Write a program to check if an element exists within a tuple.

52.Write a Python program to accept string and remove the characters which have odd
index values of a given string using user defined function.

53.Write a program to accept and convert string in uppercase or vice versa.

OR
s=input("Enter a string: ")
print("The original string: ",s)

new_str=""
for i in range (len(s)):
if s[i].isupper():
new_str+=s[i].lower()
elif s[i].islower():
new_str+=s[i].upper()
else:
new_str+=s[i]
print('convert String: ',new_str)

54.Write a program to read the contents of a file in reverse order and display the size of
file.
55.Write a program to perform the add and remove operation on a set.

56.Write a program to count the number of blank spaces in a text file.

57. Write a program to get a single string from two given strings and swap the first two characters of each
string.
Sample String: 'abc', 'xyz'
Expected Output: xycabz

58.Write a program to read the contents of a file in reverse order and display the size of
file.
# Open the file in write mode
import os.path
f1 = open("output.txt", "w")
with open("Reverse.txt", "r") as myfile:
data = myfile.read()
data_1 = data[::-1]
f1.write(data_1)

f1.close()
size1=os.path.getsize("Reverse.txt")
print('The file size:',size1)

59.Write a python program which accept word and count the frequency (occurrences) of
given word in a file.
60. Write a program to create a union of sets.

You might also like