0% found this document useful (0 votes)
8 views59 pages

Programming With Python Journal - 33599

The document outlines a comprehensive practical guide for learning Python programming, covering topics such as setting up the Python IDLE, conditional constructs, loops, string manipulation, lists, dictionaries, functions, file handling, exception handling, regular expressions, and database handling. Each section includes specific programming tasks and examples to demonstrate the concepts. The document serves as a structured curriculum for practical Python programming exercises.

Uploaded by

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

Programming With Python Journal - 33599

The document outlines a comprehensive practical guide for learning Python programming, covering topics such as setting up the Python IDLE, conditional constructs, loops, string manipulation, lists, dictionaries, functions, file handling, exception handling, regular expressions, and database handling. Each section includes specific programming tasks and examples to demonstrate the concepts. The document serves as a structured curriculum for practical Python programming exercises.

Uploaded by

inromrear
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Index Page:

Sr. Description Page Date Faculty


No No Signature
1 Installing and setting up the python IDLE 03 31/07/23
interpreter. Executing simple statements
like expression statements (numeric and
Boolean types), assert, assignment, delete
statements, the print function for output,
the input function.
2 Programs based on conditional constructs 09 07/08/23
(if, if else, if elif else, nested if).
3 Programs based on for statement and the 15 21/08/23
range function, using break and continue
statements.
4 Programs based on the while statements. 19 04/09/23
5 Programs related to string manipulation. 22 11/09/23
6 Programs related to lists and list 30 18/09/23
comprehensions.
7 Program related to dictionaries. 35 06/09/23
8 Programs related to functions. 38 08/10/23
9 Programs to read and write files. 40 16/10/23
10 Program to demonstrate exception 48 17/10/23
handling.
11 Program to demonstrate the use of 49 19/1023
regular expressions.
12 Programs related to database handling. 51 20/10/23

2
PRACTICAL 1: BASICS
⮚ Executing simple statements like expression statements (numeric
and Boolean type)

⮚ OPERATOR PRECEDENCE AND ASSOCIATIVITY

⮚ ASSERT STATEMENTS

3
⮚ ASSIGNMENT STATEMENT

⮚ DELETE STATEMENT

4
5
⮚ PRINT FUNCTION

1. Write a python program to declare three variables with values (i.e,


principle,Rate of interest and No of years) and display the simple interest
amount(Script mode).

2. Write a python program to declare a variable “Name check” assign a string


value to [Link] the use of assert statements to check the correct name
stored in variable.

3. Demonstrate working of del()

6
4. Write a python program to display the value stored in
variables (Names,Class,Address,Date of Birth).

INPUT FUNCTION

1. Write a python program to take input form user and perform basic
arithmetic operations.

7
2. Write a python program to take the input (i.e, radius of a circle) from the
user and display the area of a circle and circumference of a circle.

3. Write a python program to take a input (i.e. length and breadth) from the
user and display the area of a rectangle.

8
4. Write a python program to take the input (i.e. table of) from the user
and display multiplication table of it.

9
Get Multiple inputs from a user in one line
5. Write a python program to take the input (i.e. Student name, Class, Roll no,
Date of birth, Address, Contact no) from the user and display the ID card
Details.

PRACTICAL 2: CONDITIONAL STATEMENTS


1. Take a number from user and write a program to check whether a number
is odd or even.
CODE AND OUTPUT:

10
2. Take three inputs from user for three sides of triangle. Write a program
to check whether triangle is equilateral, isosceles or scalene.
CODE AND OUTPUT:

3. Generate a Student Report Card, by taking inputs from the student as


follows: Check percentage with grade, Student first name and last name,
Course, sem, roll no, and Marks of 5 Subjects. Calculate the following and
provide the: i) Percentage
percent
>=80

11
>=70
>=60
>=50
>=40
<40 ii)
Grade
grades
O
A
B
C
D
F
iii) Status: PASS or FAIL.

CODE AND OUTPUT:

12
13
4. Write a python program to accept two numbers from the user and check if it
is a positive or negative integer. If it is positive then compare the 2 numbers
and print the result(greatest).
CODE AND OUTPUT:

5. Python Program to implement the Rock, Paper, Scissor game.


CODE AND OUTPUT:

14
15
PRACTICAL 3: FOR STATEMENTS

1. Write a program to the sum of numbers from 1 to n where n is


user input.
Code:

Output:

2. Write a program to print the sum of series


y=x^1+x^2+x^3+…x^n where x and n are user inputs.
Code:

Output:

16
3. Write a program to accept a number and check whether it is prime.
Code:

Output:

4. Write a program to print Fibonacci series for n terms.

Code:

17
Output:

5. Write a program to accept a string and display characters that


are present at even index.
Code:

Output:

18
6. Write a program to print the below given pattern
*
**
***
****
*****
Code:

Output:

19
PRACTICAL 4: WHILE STATEMENTS
1. Write a program to accept a number and print a factorial of a number.
Code:

Output:

2. Write a program to accept a number and check if it is palindrome


or not.
Code:

20
Output:

3. Write a program to create a menu driven banking program. The user


should be able to deposit, withdraw, and check balance with necessary
conditions in place.
Code:

21
Output:

4. Write a program to accept numbers from user and calculate sum


of numbers until user enters zero.
Code:

22
Output:

PRACTICAL 5: STRING FUNCTIONS

Aim: String operations & String Functions.

String Operations

1. Assignment Operator “=”

Code and Output:

23
2. Concatenate Operator “+”.

Code and Output:

3. String Repetition Operator “*”.

Code and Output:

4. String Slicing Operator “[ ]”.

Code and Output:

24
5. String Comparison Operator “==” & “!=”.

Code and Output:

6. Membership Operator “in” & “not in”.

Code and Output:

25
String Functions

1. upper ():

Code and Output:

2. lower()

Code and Output:

3. capitalize()

Code and Output:

26
4. len()

Code and Output:

5. count()

Code and Output:

6. find()

Code and Output:

27
7. center()

Code and Output:

8. replace()

Code and Output:

9. join()

Code and Output:

10. strip()

Code and Output:

28
11. islower()

Code and Output:

12. isupper()

Code and Output:

13. isalnum()

Code and Output:

29
14. isdigit()

Code and Output:

15. isspace()

Code and Output:

16. isprintable()

Code and Output:

17. format()

Code and Output:

30
PRACTICAL 6: LISTS FUNCTIONS

▪ LISTS OPERATORS

#Length(len)

#Concatention

#Repetition

#Membership

# Slicing

31
LIST GENERAL FUNCTIONS:-
# Length

#Max & #Min

#List(seq)

List Specific Functions:-


#Append

#Count

# Extend

32
#Index

#Insert

#Pop

#remove

#reverse

#sort

#Sort & Reverse

33
#copy

#append(list)

#List comprehension

# Update

#Lambda

34
# Upper and lower()

# Sortlist()

35
PRACTICAL 7: DICTIONARY
1. #create dictionary

2. #len()-length of dictionary

3. #Access dictionary items

4. #keys() - get all keys of a dictionary

5. #values() - get all values of a dictionary

36
6. #items() - will return each item in a dictionary, as tuples in a list

7. #Change items

8. #Add dictionary items

37
9. #Remove dictionary items

10. #clear()- clear dictionary content

11. #copy()

38
12. #Nested Dictionaries
#Access nested dictionary items

PRACTICAL 8: FUNCTIONS
1) Implement factorial using anonymous function.
CODE AND OUTPUT:

2) Write a program to display the payslip of an employee, where employee


id and basic pay is to the function; DA=90%basicpay, HRA=40%basicpay,
TA=20%basicpay and NET salary= DA+TA+HRA+basicpay.
CODE AND OUTPUT:

39
3) Implement a function in python to check if a number is Krishnamurthy or
not.
CODE AND OUTPUT:

4) Implement conversion from decimal to binary using recursive function.

40
CODE AND OUTPUT:

PRACTICAL 9: FILE HANDLING


Aim: - File handling in Python.

• To read the file and close.

• To close the file without using close () function.

• To close the file with using for loop.

41
• To write the file.
CODE:

OUTPUT:

• To write with write lines () function.

CODE:

OUTPUT:

42
• To Append

CODE:

OUTPUT:

• To read file without using read () function. (using


loop function)

43
• Program to read numbers
from input file and write its
CODE: square to output file.

OUTPUT:

44
• Write a python program with an input file comprising of an
employee details namely employee name, employee code,
basic salary. Create an output file as pays lip will contain
employee name, employee code, basic salary, da, ta, hra
and net salary.

CODE:

OUTPUT:

45
❖ To check the current working directory with the help of module
and its function.

❖ To change the current working directory.

❖ To make directory.

46
❖ To rename a folder.

OUTPUT:

❖ To remove

directory. CODE:

OUTPUT:

❖ To remove
files. CODE:

47
Output: -

Before Execution: -

After execution: -

48
PRACTICAL 10: EXCEPTION HANDLING
1. Write a program to catch ZeroDivisionError, Name error

TO CATCH THE ZERO DIVISION ERROR

TO CATCH THE NAME ERROR

2. Write a program to catch Indexerror, typeerror, valueerror


and finallyblock

TO CATCH INDEX ERROR

TO CATCH TYPE ERRROR

49
TO CATCH VALUE ERROR

PRACTICAL 11: REGULAR EXPRESSION


Program to demonstrate the use of regular expressions.

1.1 Username-Starts with a lowercase alphabet and can contain minimum


8 character and maximum 15 character the after starting letter can be any
alphanumeric character
1.2 Mobile number – contain 10 digits
1.3 Email I’d Format

CODE AND OUTPUT:

50
2. Write a Python function text_match() that matches a string that has
an ‘a’ followed by zero or more occurrence #of anything ,ending in
‘b’.

CODE AND OUTPUT:

51
3. Write a python program to accept an address and replace
occurrences of Road by Rd.,District by Dst. And Street by
St.

CODE AND OUTPUT:

PRACTICAL 12: DATABASE HANDLING


* AIM :- To learn database connectivity in python.
* CODE & OUTPUT :-

##Write a database program to perform the following:-

- Show all databases in DBMS.

- Create a database named “Company”.

52
- Create a table Employee in Company Database(empid

int, empname varchar(50), designation varchar(50),

basic int).

- Insert 10 records into employee table.

- Display all records of employee table.

- Display the employees details with designation as


entered by the user at runtime.

- Display the employee details with basic < 20000.

- Update the basic of Manager by 30%.


● CODE & OUTPUT :-

##INSTALLATION OF MYSQL CONNECTOR.

##TO SHOW THE DATABASES IN ‘DBMS’.

53
##TO CREATE DATABASE “COMPANY”.

54
##TO CREATE A TABLE EMPLOYEE IN COMPANY
DATABASE(EMPID INT, EMPNAME
VARCHAR(50), DESIGNATION VARCHAR(50),
BASIC INT).

55
##TO INSERT 10 RECORDS INTO EMPLOYEE TABLE.

56
##TO DISPLAY ALL RECORDS OF EMPLOYEE TABLE.

##TO DISPLAY THE EMPLOYEES DETAILS


WITH DESIGNATION AS ENTERED BY THE
USER AT RUNTIME.

57
##TO DISPLAY THE EMPLOYEE DETAILS WITH BASIC
< 20000.

##TO UPDATE THE BASIC OF MANAGER BY 30%.

##BEFORE EXECUTION :-

58
##AFTER EXECUTION :-

59
60

You might also like