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

Python Questions For Beginners

Uploaded by

aishwarya.pawar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views

Python Questions For Beginners

Uploaded by

aishwarya.pawar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Python Programming

Practical Questions

1. Write a program to create the separate list of digits from the original list which contains
digits and alphabets using list comprehensions. (Input List = ['a', 'b', 2, 43, 'Hi', 900, 'xyz'],
output list = [2, 43, 900])
2. Write a program to create the separate list by taking the first letter of each word in the
original string using list comprehensions. (Input List = ['Sanjay', 'Ajay', 'Vijay', 'Ganesh',
'Nilesh'], output list = ['S', 'A', 'V', 'G', 'N'])
3. Write a program to replace digits in a string with their equivalent words.
Input String = "Python 3 is 2 easy 4 learning"
Output String = "Python three is two easy four learning."
4. Write a menu driven program to implement Add, Delete, Append, View and Quit operation
on list.
5. Write a menu driven program to show Union, Intersect, Difference, Symmetric difference
operations on set.
6. Write a function average() which will return the average of the numbers inputted by the
user.
7. Write a Python program to add two matrices.
8. Write a Python program to transpose the matrix.
9. Write a program to multiply two matrices.
10. Write a Python program to get a list, sort it in increasing order by the last element in each
tuple from a given list of non-empty tuples.
Sample List : [(2, 5), (1, 2), (4, 4), (2, 3), (2, 1)]
Expected Result : [(2, 1), (1, 2), (2, 3), (4, 4), (2, 5)]
11. Write a program to remove all the duplicate items from a list.
Input List = [10,20,30,20,10,50,60,40,80,50,40]
Output List = [10, 20, 30, 50, 60, 40, 80]
12. Write a program to create a list of words from the given string, which are less than size 'n'.
Input String : "Python programming is fun. I like python programming very much."
Input: n = 6
Output List = ['is', 'fun.', 'I', 'like', 'very', 'much.']
13. Write a function nMax() which will return the maximum between the entered numbers.
14. Write a program to find the factorial of a number using recursion.
15. Write a program to generate a Fibonacci sequence using recursion.
16. Write a program to print the sum of natural numbers using recursion.
17. Let us assume the tuples in the list based on their last item. Using sorted() function and
lambda, sort the tuples by their last item.
18. Write a message encoder-decoder program using a nested function. Define the outer
function as encodeMsg() which will accept a message to encode and a key to encode with.
Define the inner function as encoder() which will encode the message with a given key
(how to encode, that is up to you). The outer function then returns this encoded message to
the main program. Similarly, do the task of decoding the encoded message by writing the
outer function as decodeMsg() and the inner function as decoder().
19. Implement a generator called “squares” to yield the square of all numbers from (a) to (b).
Test it with a “for” loop and print each of the yielded values.
20. Create a generator to yield all the odd numbers from 1 to (n). Test it with a “for” loop and
print each of the yielded values.
21. Create a generator which will generate the next even number from the number passed. For
example, if the number passed is 3, then the next even number is 4; if the number passed is
6, then the next even number is 8.
22. Create a generator which will generate the next prime number from the number passed.
For example, if the number passed is 14, then the next prime number is 17.
23. Create a decorator “smart_add” which will add two operands only if they are of the same
data type (i.e. the smart add).
24. Create a decorator “works_for_all()” which is used to decorate the regular function
“adder”. The adder function can accept any number of arguments and will add them.
Implement the “inner()” function for decoration as per your choice.
25. Write a generator function my_range(start, stop, step), which will accept three arguments
as start, stop, and step, and generate a given range (means exactly the same as that of the
built-in range function).
26. Write a program to guess a number generated randomly.
27. Write a program to accept decimal number and print its octal and hexadecimal equivalent
28. Write a program to implement Rock, Paper, Scissor game between human and computer.
Make use of the random module.
29. Write a program to guess a sum of eyes on two dices. Roll the dice using a random
module.
30. Write a program to draw 3 cards randomly from the deck of 52 cards. The card you draw
should be unique.
31. Create a class “Bank” having attributes “Bank Name”, “Branch”, “City”, “Manager
Name” and methods “Change of Manager Name” and “Display Details”. Write a
constructor to initialize instance variables. Write a main program to demonstrate the use of
Bank class.
32. Create a class “Employee” which inherits “Person” and “Bank” class. (i.e. multiple
inheritance). ThenEmployee class contains attributes “Years of experience”, “Date of
Joining”, “Skills” and methods “Update years of experience”, “Update Skills”, “Display
Employee Details”. Write a main program to demonstrate the use of Employee class.
33. Write a Python program to check the validity of a password given by user. The password
should satisfy following criteria:
i) Contain at least 1 letter between a and z
ii) Contain at least 1 number between 0 and 9
iii) Contain at least 1 letter between A and Z
iv) Contain at least 1 character from $, #, @,* Minimum length of password : 8
Maximum length of password : 20
34. Write a program for extracting email address from a given webpage
35. Write a program to validate URL using regular expression.
36. Write a program to validate PAN card number.
37. Write user defined exception program in python which will find the factorial of a number.
If number is less than zero it should raise the exception as ‘Invalid Input’.
38. Write user defined exception program in python which will accept age as an input from the
user and check whether the user is eligible for voting or not. If age < 18 it should raise the
exception as ‘Not eligible for voting’.
39. Write a multithread program, where one thread prints square of a number and another
thread prints cube of numbers. Also display the total time taken for execution.
40. Write a python program which will continuously accept some input from the user and
write it into the file line by line until user type the word ‘exit’.
 Write a program to copy a text file.
 Write a program to read and write binary file.
 Write a program to read and write a csv file.
 Write a program to read and write a config file.
 Write a program to write log information in a file.
 Write a program to log stack traces in a file.
41. Write a python program to count the number of lines, words and characters in a file.
42. Create class called, library with data attributes like Acc-number publisher, title and author,
the methods of the class should include [4] i) Read ( ) - Acc- number, title, author,
publisher. ii) Compute ( ) - to accept the number of day late, calculate and display the fine
charged at the rate of Rupees 5/- per day. iii) Display the data.
43. Develop a program to print the number of lines, words and characters present in the given
file? Accept the file name from user. Handle necessary exceptions.
44. Write a mongoDB program to Create a “Books” collection having fields: title, Author (a
list),Publisher, PubAdress (a dict with keys like area, city, country), Price, ISBN. Accept
input from user to insert documents.
 Write a mongoDB program to update the “Books” collection.
 Write a mongoDB program to retrieve documents in different formats with filtering.
 Write a mongoDB program to delete selected document(s).
45. Write a python program using mongoDB database to create a “student” collection having
fields: Student-ID, Name, Course, Mobile, Address. (a dict with keys like area, city,
country, pin) Accept input from user to insert documents
46. Write a python program to perform following operations. on MongoDB Database.
i) Create collection “EMP” with fields: Emp-name, Emp- mobile, Emp, sal, Age
ii) insert 5 documents.
iii) Find the employees getting salary between 5000 to 10000.
iv) Update mobile number for the employee named as “Riddhi”
v) Display all employees in the order of “Age”
47. Write a program for synchronization of threads using RLOCK. Accept the two numbers
from user and calculate factorial of both numbers simultaneously
48. Write a python program
 To remove all leading ‘zeros’ from an IP address
 To find all 5 character long words in a string Accept string from user.

49. Write a Python program to create a Django view that displays a simple welcome message
like "Welcome to My Site!" in the browser.
50. Write a Python program to use Django templates to create a home.html file with a dynamic
greeting that shows the current date and time.
51. Write a Python program to set up a URL pattern for a contact page that displays a basic
"Contact Us" view in Django.
52. Write a Python program to create a form in Django to gather feedback from users with
fields like name, email, and comments.
53. Write a Python program to add user login functionality to a Django project. Set up a
simple login page where users can enter their username and password.
54. Write a Python program to create a protected view that only logged-in users can access,
displaying a message like "Welcome, [username]!".
55. Write a Python program to set up basic user authentication in Django. Create a registration
page where new users can sign up, a login page, and a logout option.

Question on - Numpy & Pandas


1. Write a program to demonstrate various ways of creating a numpy array.
2. Create a 2-D numpy array and perform the indexing and slicing on it.
3. Demonstrate the use of universal array function.
4. Perform element wise operation, matrix product and array transposition on numpy array.
5. Demonstrate the use of various numpy array input and output functions.
6. Demonstrate the use of array joining and splitting functions.
7. Create a 5x5 2D array, whose border elements are 1's.
8. Create an Numpy Array containing elements from 5 to 30 but at equal interval of 2. And
select the elements which are less than 10.
9. How to find the position of missing values in numpy array? How to find the number of
missing values in numpy array?
10. How to create a series from a list, numpy array and dict? Also demonstrate how to create a
series with labeled index.
11. How to assign name to the series as well as it’s index? How to apply arithmetic operators
on each and every element of a series?
12. How to get the items of series A not present in series B? How to get the items not common
to both series A and series B? How to get the items common to both series A and series B?
13. How to get frequency counts of unique items of a series?
14. How to find the positions of numbers that are multiples of 3 from a series? and count the
number of missing values in a series? How to replace the missing values in a series with
their averages?
15. How to check whether the series contains any missing values? and count the number of
missing values in a series? How to replace the missing values in a series with their
averages?
16. Make a Pandas DataFrame with two-dimensional list. How to combine many series to
form a dataframe?
17. How to reverse the columns of a dataframe? How to reverse the rows of a dataframe?
18. How to check if a dataframe has any missing values?
19. How to rename a specific columns in a dataframe? How to find only those columns whose
data type is ‘object’?
20. How to know the data type of each column of a dataframe? How to find only those
columns whose data type is ‘object’?
21. .How to count the number of missing values in a dataframe? Drop the rows/columns where
at least one element is missing. Drop the rows/columns where all elements are missing.
22. How to read the data from csv file and create a dataframe? (Use churn_data1.csv file).
Display first 10 rows only. Display a list of all the columns.

23. Print a concise summary of a DataFrame. Generate descriptive statistics of DataFrame


columns having numeric datatype/string/object datatype.
24. Demonstrate how the read the part of a csv file and create a dataframe. (Read only few
columns/rows).
25. Display the number of missing values in each column. Fill missing values with averages
for the numeric columns.
26. How to sort the dataframe by rows/columns.
27. Select customers who live in France and have churned (means Exited = 1). Also display
total number of rows found.
28. Select customers whose Balance is in the range of 8000 to 10000 using query function.

29. Find the customers opted for tenure of 4, 6, 9, and 10 years only.

30. Insert a new column ‘custType’ into dataframe with all values as NaN.

31. Update the ‘custType’ with value 'P' as privileged customer whose credit score is > 700.

32. Find the total number of unique values in the ‘Geography’ column.

33. Display customers whose age is < 30 years and credit score is > 600.

34. Draw line graph using matplotlib and decorate it by adding various elements like title etc.

35. Draw multiple trends line graph using matplotlib and decorate it by adding various
elements.

36. Draw bar plots using matplotlib and decorate it by adding various elements.

37. Draw multi series bar charts using matplotlib and decorate it by adding various elements.

38. Draw Pie chart/histogram/scatter plot using matplotlib.

You might also like