You are on page 1of 99

Session 2023 -24

SRI GURU NANAK PUBLIC SCHOOL

Session 2023-24

PYTHON

PROGRAMMING FILE

MADE BY-

NAME :ARYAN

CLASS : XII-Science

ROLL NO :________

1
Session 2023 -24

LIST OF PRACTICALS :

S.NO. AIM
1 Write a program to show entered string is a palindrome or not.
2 Write a program to show statistics of characters in the given line(to counts the
number of alphabets ,digits, uppercase, lowercase, spaces and other characters).
3 WAP to show sum of all odd numbers and even numbers from the list entered by
user.
4 Write a program to display frequencies of all the element of a list entered by user.

5 Write a program to display those string which are starting with ‘A’ from the given
list.
6 Write a program to find and display the sum of all the values which are ending with
3 from a list.
7 Write a program to show sorting of elements of a list step-by-step , using bubble
sorting technique.
8 Write a program to input total number of sections and stream name in 11th class and
display all information on the output screen.
9 Write a program to input name of ‘n’ countries and their capital and currency store, it
in a dictionary and display in tabular form also search and display for a particular
country.

10 Write a function in python, which accept a number from user to return True, if the
number is a prime number else return False. Use this function to print all prime
numbers from 1 to 100.
11 WAP to show functionality of a basic calculator using functions.
12 Write a program to enter the numbers and find Linear Search, Binary Search, Lowest
Number and Selection Sort using array code with user defined functions.
13 Write a program to find factorial of entered number using library function fact().
14 Write a program to call great func() to find greater out of entered three umbers, using
import command.
15 Write a random number generator that generates random numbers between 1 and 6
(simulates a dice). Throw the two dices for 10 times and print their total.

16 Write a program to show and count the number of words in a text file ‘DATA.TXT’
which is starting/ended with an word ‘The’, ‘the’.
17 Write a program to read data from a text file info.TXT, and display each word with
number of vowels and consonants.
18 Write a program to read data from a text file value.TXT, and display word which
have maximum/minimum characters.
2
Session 2023 -24

19 Write a program to create a text file and print the lines starting with ‘T’ or ‘P’. (Both
uppercase and lowercase).
20 Write a program to write a string in the binary file “comp.bin” and count the number
of times a character appears in the given string using a dictionary.
21 Write a program that will write a string in binary file "school.bin" and
display the words of the string in reverse order.
22 Consider a binary file “Emp.bin” containing details such as empno:
ename:salary(separator‘:’).Write a python function to display details of those
employees who are earning between 20000 and 40000.
23 Create a binary file with roll number, name and marks. Input a roll number and
update the marks.
24 Write a program to insert list data in CSV File and print it.

25 Read a CSV file (containing item no, name, rate, QOH) from hard disc and print all
the items whose rate is between Rs 500 and Rs 1000.
26 Read a CSV file from hard disc and print all the details on the screen.
27 Create a CSV file by entering user-id and password, read and search the password for
given userid.
28 Write a program to insert item on selected position in list and print the updated list.
29. Write a program to show push and pop operation using stack.
30. Julie has created a dictionary containing names and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the
following operations:
● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
● Pop and display the content of the stack.
31. Raghav has created a vocabulary list. You need to help him create a program with
separate user defined functions to perform the following operations based on this list.
(a) Traverse the content of the list and push the entries having less than 7 characters
into a stack.
(b) Pop and display the content of the stack.
For example: If the sample content of the list is as follows:
W=[‘Elucidate’,’Haughty’,’Pacify’,’Quip’,’Rapport’,’Urbane’,’Young’,’Zenith’]
Sample output of the code should be:Pacify, Quip, Urbane,Young, Zenith

3
Session 2023 -24

32. Write a program A company having a dictionary of various Departments and Number
of Computers (PC) available as key-value pairs.Write a program, with
separate user defined functions to perform the following operations:
(a) Push the keys (name of the department) of the dictionary into the stack where the
corresponding value (number of PC) is 25 or more.
(b) Pop and display the content of the stack.
For eg: setup={“HR”:10,”QUALITY”:25,”SUPPORT”:50,
”PRODUCTION”:20,”SUPPLY”:25}
Then the output should be: QUALITY SUPPORT SUPPLY
33. Alam has a list containing 10 integers. You need to help him create a program with
separate user defined functions to perform the following operations based on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be: 2 98 56 34 12
34. Nandu has created a dictionary containing countries and continent as key value pairs
of 6 countries. Write a program, with separate user defined functions to perform the
following operations:
● Push the keys (name of the country) of the dictionary into a stack, where country
belongs to continent “ASIA”.
● Pop and display the content of the stack.
For example: If the sample content of the dictionary is as follows:
R={"UK":”EUROPE, "INDIA":”ASIA”, "CHINA":”ASIA”,
"EGYPT":”AFRICA”, "CUBA":”AMERICA”, "JAPAN":”ASIA”}
The output from the program should be: JAPAN CHINA INDIA
35. In MySql, Create a database named SGNPS, under this database create table named
STUDENT with admno,name,class,sec,rno,address. Insert two rows of data. Write
Python program to establish connection to database, update record with new values
for the entered admno.
36. Write a Program to show database connectivity of python with MySQL database to
perform insertion , updation , deletion and retrieval .

4
Session 2023 -24

# AIM 1:WAP to accept a string and whether it is a palindrome or not.

#CODING :

5
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. s String To accept a string
2. l Integer To get length of a string
3. p Integer To get length-1
4. Index Integer To assign the starting point of the string
5. len() Integer To calculate length of a string

6
Session 2023 -24

#AIM2 : WAP to counts the number of alphabets ,digits, uppercase, lowercase, # spaces and
other characters(status of a string).

#CODING :

OUTPUT:
7
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. str 1 String To accept a string from user
2. n Boolean To check the Number of alpha & digit
3. c Boolean To accept alpha value from user
4. u Boolean To accept Capital alpha from user
5. l Boolean To accept Small alpha from user
6. d Boolean To accept digit from user
7. isalnum String To check the alpha and digit
8. isupper String To check the uppercase
9. islower String To check the lowercase
10. isalpha String To check the alpha
11. isdigit String To check the digit
12. isspace String To check the space

#AIM3:WAP to show sum of all odd numbers and even numbers from the list entered by
user.

#CODING:
8
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. l List To accept a list
2. sumo Integer To accept even no
9
Session 2023 -24

3. sume Integer To accept odd no


4. z Integer To accept the length
5. a Integer To accept the elements
6. append List To add a value at the end

#AIM 4 :WAP to display frequencies of all the element of a list entered by user.

#CODING :

10
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose

11
Session 2023 -24

1. l List To accept a list from user


2. l1 List To accept a list from user
3. l2 List To accept a list from user
4. z Integer To accept a length of list
5. a Integer To accept a elements of list
6. X Integer To count a no of elements individually
7. append list To add the value at the end

#AIM 5: WAP to display those string which starts with ‘A’ from the given list.

12
Session 2023 -24

#CODING :

OUTPUT:

VARIABLE AND FUNCTION USED :

13
Session 2023 -24

Sno Variable / Function Name Data type Purpose


1. l List To accept a list
2. count Int To count the elements which are
starting from A

14
Session 2023 -24

“AIM 6:WAP to find and display the sum of all the values which are ending with 3 from a
list entered by user”’

#CODING :

OUTPUT:

15
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. L List To accept a list from user
2. sum Int To add the numbers ending with 3
3. l Int To accept the length of list
4. a Int To accept the number greater than 10
5. x Len To check the length of appended list
6. append list To add value at the end

16
Session 2023 -24

#AIM 7: Write a AIM to show sorting of elements of a list step-by-step, using bubble sorting
technique.

#CODING :

OUTPUT:

VARIABLE AND FUNCTION USED :


17
Session 2023 -24

Sno Variable / Function Name Data type Purpose


1. a List To accept the list from user
2. len int To check the length of a list

‘“AIM8 : WAP to input total number of sections and stream name in 11th class and display
all information on the output screen.”’
18
Session 2023 -24

#CODING :

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose

19
Session 2023 -24

1. n Int To accept the total no of sections


2. a Text To accept the first section name from
user
3. b text To accept the second section name
from user

#AIM9: WAP to input name of ‘n’ countries and their capital and currency store, it in a
dictionary and display in tabular form also search and display for a particular country.’”

#CODING :
20
Session 2023 -24

OUTPUT:

21
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. d1 Dict To accept a dictionary from user
2. n int To accept a no of enteries
3. c Text To accept a country name
4. cap Text To accept a capital of a country
5. curr text To accept a currency of a country
6. l text To accept the values of keys
7. x text To searced the country

‘“AIM10 : Write a function in python, which accept a number from user to return True, if
the #number is a prime number else return False. Use this function to print all prime
numbers #from 1 to 100.

22
Session 2023 -24

#CODING :

OUTPUT:

23
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. num int To enter a positive number from user
2. prime int To check the number prime or not

‘“AIM11 : WAP to show functionality of a basic calculator using functions.

24
Session 2023 -24

CODING:

OUTPUT:

25
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. add int To add two numbers entered by the
user
2. sub int To subtract two numbers entered by the
user
3. pro int To multiply two numbers entered by
the user
4. dvd int To divide one number by other entered
by the user
5. pow int To evaluate the power of the number
6. num1 int To enter the first number from user to
perform function on it
7. num2 int To enter the second number from user
to perform function on it
8. ch int To enter the choice from the user
#Aim12:WAP to enter the numbers and find Linear Search, Binary Search, Lowest Number
and#Selection Sort using array code using User defined functions in a menu driven program.
26
Session 2023 -24

CODING:

27
Session 2023 -24

28
Session 2023 -24

29
Session 2023 -24

OUTPUT:

30
Session 2023 -24

31
Session 2023 -24

32
Session 2023 -24

33
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. Ch string To accept a value
2. X string To accept a value

34
Session 2023 -24

“““AIM13: Write a AIM to find factorial of entered number using library function
fact().”””

35
Session 2023 -24

OUTPUT :

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. n int To enter a value.
2. x int To enter a number from user.
3. Fact() It is a function used to find factorial of
a number.

36
Session 2023 -24

#AIM14 : Write a AIM to call great function to find greater out of entered three numbers,
using import command.

#CODING :

37
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. greater int To check the greater no in given three
numbers.
2. x int To enter the first number by user.
3. y int To enter the second number by user.
4. z int To enter the third number by user.

38
Session 2023 -24

#AIM15 : Write a random number generator that generates random numbers between 1
#and 6 (simulates a dice). Throw the two dices for 10 times and print their total.
#CODING :

OUTPUT:

39
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. randint random To generate randoms integers.
2. s1 int To store integer values.
3. n int To store integer values.
4. z int To store integer values.
5. s int To store integer values.

40
Session 2023 -24

#AIM16 :Write a aim to show and count the numbers of words in a text file “DATA.TXT”
Which is starting/ended with an word ”the”,”The”,”My”,”my”,”He”,”he”,”’They”,”they”.
#CODING :

OUTPUT:
41
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() To open a text file “data”.
2. read() To read a text file “data”.
3. split() string To split the string.
4. len() int To count the length of string.
5. a int To count the number of “the” or “The”.
6. b int To count the number of “he” or “He”.
7. c int To count the number of “my” or “My”.
8. d int To count the number of “they”or
“They”.
9. startswith() string To check the string start with
the,my,he,they.
10. endswith() string To check the string ends with
The,He,They,My.
11. f1 It is a variable used to open a file.
12. s It is a variable used to read a file.
#AIM 17 : WAP to read data from a text file info.txt, and display each words with number
#of vowels and consonants.
42
Session 2023 -24

OUTPUT:

43
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a
file”info”.
2. read() It is a function used to read a file”info”.
3. split() string To split the string.
4. len() int To count the length of string
5. isalnum() string To check whether string contains alpha
or numeric values or not.
6. f1 It is a variable used to open a file.
7. s It is a variable used to read a file.
8. countV int To count the numbers of vowels in file.
9. countC int To count the numbers of consonants in
file.
10. words string It is a variable used to split a string.

#AIM 18 : WAP to read data from a text file value.txt, and display word which have
maximum/minimum characters.
44
Session 2023 -24

#CODING :

OUTPUT:
45
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a
file”value”.
2. read() It is a function used to read a
file”value”.
3. split string To split the string.
4. len() int To count the length of string.
5. f1 It is a variable used to open a
file”value”.
6. s It is a variable used to read a
file”value”.
7. words string It is a variable used to split the string.
8. maxC count To count the length of maximum words
character in file.
9. minC count To count the length of minimum words
character in file.
10. minfinal string To display the word having maximum
length .
11. maxfinal string To display the word having minimum
length.

46
Session 2023 -24

““AIM 19 : Write a program to create a text file and print the lines starting with ‘T’ or ‘P’.
(Both uppercase and lowercase).’’’

#CODING :

47
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a file”strt”.
2. readlines() list It is a function used to read lines in list
form.
3. close() It is a function used to close the
file”strt.”
4. c int To count the no of lines starting with
“t” or “p”.
5. f It is a variable used to open a file”strt”.
6. x It is a variable used to readlines.

48
Session 2023 -24

#AIM 20 : Write a AIM to write a string in the binary file “comp.bin” and count the
number of times a character appears in the given string using a dictionary.

#CODING :

49
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. str string To give a string in a file”comp”.
2. f1 It is a variable in which we call a open
function
3. dump() It is a function used to write anything in
binary file.
4. load() It is a function used to read anything in
binary file.
5. d dictionary To give a empty dictionary.
6. close() It is a function used to close a
file”comp”.
7. open() It is a function used to open a
file”comp”.

50
Session 2023 -24

‘’‘AIM 21 : Write a program that will write a string in binary file "school.dat" and

display the words of the string in reverse order.

Example: myString="Silicon Institute of Technology"

Output: Technology of Institute Silicon ‘’’

#CODING :

51
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. str String To give a string in a program.
2. f1 It is a variable in which we open a file.
3. open() It is a function used to open a
file”school”.
4. close() It is a function used to close a
file”school”.
5. dump() It is a function used to write anything in
binary file.
6. load() It is a function used to read anything in
binary file.
7. str1 It is a variable in which we use load
function.
8. l list It is a variable used to change the string
into list.
52
Session 2023 -24

‘’’AIM 22 : Consider a binary file “Emp.dat” containing details such as empno:


ename:salary(separator‘:’).Write a python function to display
details of those employees who are earning between 20000 and 40000. ‘’’

#CODING :

OUTPUT:

53
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. fin It is a variable in which we call a
function open().
2. dict dictionary To give a dictionary in a file.
3. open() It is a function used to open a
file”emp”.
4. close() It is a function used to close a
file”emp”.
5. x It is a variable in which we call a
function load().
6. dump() It is a function used to write anything in
binary file.
7. load() It is a function used to read anything in
binary file.

54
Session 2023 -24

#AIM 23: Create a binary file with roll number, name and marks. Input a roll number and update
the marks.
#CODING :

OUTPUT:

55
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a
file”score”.
2. dump() It is a function used to write anything in
binary file.
3. close() It is a function used to close a
file”score”.
4. load() It is a function used to read anything in
binary file.
5. d1 Dictionary To give a dictionary in a file.
6. f It is a variable in which we call a
function open().

56
Session 2023 -24

#AIM 24 : Write a program to insert list data in CSV File and print it
#CODING :

57
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. writer() It is a function used to write anything in
csv file.
2. writerows() It is a function used to write anything in
csv file but in list format.
3. writerow() It is a function used to write anything in
csv file but in string format.
4. fields list To give a list in a file.
5. filename It is variable used to call a open().
6. reader() It is a function used to read anything in
csv file.
7. open() It is a function used to open a csv
file”mycsv”.

58
Session 2023 -24

#AIM 25: WAP to read a CSV file (containing item no, name, rate, QOH) from hard disc
and print all the items whose rate is between Rs 500 and Rs 1000.
Coding:

59
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a csv file.
2. reader() It is a function used to read anything in
csv file.
3. search() It is a user defined function for
searching.
4. close() It is a function used to close a file.
5. f It is a variable used to call the function
open().
6. a It is a variable used to call the function
reader().
7. next

#AIM 26 : WAP to read a CSV file from hard disc and print all the details on the screen
60
Session 2023 -24

#Coding:

OUTPUT:
61
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. open() It is a function used to open a csv
file”tag”.
2. Next() It is a function used to write anything in
csv file.
3. Reader() It is a function used to read in csv file.
4. f It is a variable used to call the function
open().

‘’’AIM 27 : WAP to create a CSV file by entering user-id and password, read and search the
password for given userid.’’’

62
Session 2023 -24

#CODING :

OUTPUT:

63
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. Open() It is a function used to open a csv
file”passwd”.
2. writer() It is a function used to write anything in
csv file.
3. writerows() It is a function used to write in csv file
but in list form.
4. writerow It is a function used to write in csv file.
5. file It is a variable used to call the function
open().
6. file1 It is a variable used to call the function
writer().
7. userid To enter a userid from user.
8. password To enter a password in digit from user.
9. List
10. ch To enter a choice from user to enter
more enteries or not.
11. Search_userid To enter the userid to search passwd.
12. Reader() It is a function used to read in csv file.
64
Session 2023 -24

13. found It is variable in which we give False.

‘’’AIM 28 : Write a program to insert item on selected position in list and print the updated
list.

65
Session 2023 -24

CODING:

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


66
Session 2023 -24

1. n int To enter number of items in list.


2. DATA List To give a empty list
3. item int To accept a item number.
4. e int To enter item from user
5. pos int To enter a pos from user.
6. le len To count the length data.

‘’’AIM 29 : Write a program to show push and pop operation using stack.

CODING:
67
Session 2023 -24

OUTPUT:

68
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


69
Session 2023 -24

1. push() It is a function to add element at the


end of list.
2. pop It is a function to remove element from
the end of list.
3. len() int To count the length of stack.
4. display() It is a function to show stack enteries.
5. x list To give a empty list.
6. choice int To accept choice from user.

‘’’AIM 30 : Julie has created a dictionary containing names and marks as key value pairs of
6 students. Write a program, with separate user defined functions to perform the following
operations:
● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.
70
Session 2023 -24

● Pop and display the content of the stack. ‘’’

CODING:

71
Session 2023 -24

72
Session 2023 -24

73
Session 2023 -24

OUTPUT:

74
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. push() To add the element at the end in statcs.
2. pop() To delete the element from the end in
statcs.
3. display() To print the statcs after push and pop
function are done.
4. students dict To give a empty dictionary.
5. limit int To enter a limit from user.
6. name string To enter a name from user.
7. marks int To enter a marks from user.

75
Session 2023 -24

‘’’AIM 31 : Raghav has created a vocabulary list. You need to help him create a program
with separate user defined functions to perform the following operations based on this list.

(a) Traverse the content of the list and push the entries having less than 7 characters into a
stack.
(b) Pop and display the content of the stack.
For example: If the sample content of the list is as follows:
W=[‘Elucidate’,’Haughty’,’Pacify’,’Quip’,’Rapport’,’Urbane’,’Young’,’Zenith’]
Sample output of the code should be:Pacify, Quip, Urbane,Young, Zenith’’’

CODING:

76
Session 2023 -24

77
Session 2023 -24

78
Session 2023 -24

OUTPUT:

79
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. push() To add the element at the end in statcs.
2. pop() To delete the element from the end in
statcs.
3. display() To print the statcs after push and pop
function are done.
4. try
5. except
6. vocublary To give a empty list.

80
Session 2023 -24

‘’’AIM 32 : Write a program A company having a dictionary of various Departments and


Number of Computers (PC) available as key-value pairs.Write a program, with
separate user defined functions to perform the following operations:
(a) Push the keys (name of the department) of the dictionary into the stack where the
corresponding value (number of PC) is 25 or more.
(b) Pop and display the content of the stack.
For eg: setup={“HR”:10,”QUALITY”:25,”SUPPORT”:50,
”PRODUCTION”:20,”SUPPLY”:25}
Then the output should be: QUALITY SUPPORT SUPPLY’’’

CODING:

81
Session 2023 -24

OUTPUT:

82
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. d dictionary To give a dictionary in program.
2. stack
3. append list To add the element at the end in list.
4. pop To delete the element from the end in
statcs.
5. a()
6. b()
7. len() int To count the length of the statcs/list.

83
Session 2023 -24

‘’’AIM 33 : Alam has a list containing 10 integers. You need to help him create a program
with separate user defined functions to perform the following operations based on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be: 2 98 56 34 12’’’

CODING:

84
Session 2023 -24

OUTPUT:

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. N list To give a list in a program.
2. stack list
3. append list To add the element at the end in list.
4. a()
5. b()
6. len() int To count the length of the statcs/list.
7. pop() To delete the element from the end in
statcs.

85
Session 2023 -24

‘’’AIM 34 : Nandu has created a dictionary containing countries and continent as key value
pairs of 6 countries. Write a program, with separate user defined functions to perform the
following operations:
● Push the keys (name of the country) of the dictionary into a stack, where country belongs
to continent “ASIA”.
● Pop and display the content of the stack.
For example: If the sample content of the dictionary is as follows:
R={"UK":”EUROPE, "INDIA":”ASIA”, "CHINA":”ASIA”,
"EGYPT":”AFRICA”, "CUBA":”AMERICA”, "JAPAN":”ASIA”}
The output from the program should be: JAPAN CHINA INDIA’’’

CODING:

86
Session 2023 -24

OUTPUT:

87
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. R Dictionary To give a dictionary in a program.
2. stack
3. append list To add the element at the end in list.
4. pop() To delete the element from the end in
statcs.
5. app()
6. dele()
7. len() int To count the length of the statcs/list.

88
Session 2023 -24

‘’’AIM 35 : In MySql, Create a database named student, under this database create table
named STUDENT with sid,sname,sage,marks,sclass,ssection. Insert one row of data. Write
Python program to establish connection to database, update record with new values for the
entered admno.’’’

CODING:

OUTPUT:

89
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. Connect() To connect the python interface with
mysql.
2. Cursor() It continues the connection between
python and mysql.
3. Db It is a variable used to call the function
connect.
4. Cursor_obj It is a variable used to call the function
cursor.
5. qry It is a variable in which we call a mysql
query.
6. Top_index It is a variable to store index of topper.

90
Session 2023 -24

‘’’AIM 36 : Write a Program to show database connectivity of python with MySQL


database to perform insertion , updation , deletion and retrieval .’’’

CODING:

91
Session 2023 -24

92
Session 2023 -24

93
Session 2023 -24

94
Session 2023 -24

OUTPUT:

95
Session 2023 -24

96
Session 2023 -24

VARIABLE AND FUNCTION USED :

Sno Variable / Function Name Data type Purpose


1. fetchdata() It is a user-defined function use to fetch
data from mysql.
2. adddata() It is a user-defined function use to add
data into mysql table.
3. deldata() It is a user-defined function use to
delete data into mysql table.
4. updatedata() It is a user-defined function use to
update data into mysql table.
5. udata() It is a user-defined function use to add
data into mysql table.
6. connect() To connect the python interface with
mysql.
7. cursor() It continues the connection between
python and mysql.
8. sid It is a variable to enter the id of student
from user.
9. sname It is a variable to enter name of student
from user.
10. sage It is a variable to enter the age of
student from user.
11. sSection It is a variable to enter the section of
student from user.
12. sclass It is a variable to enter the class of
student from user.
13. marks It is a variable to enter the marks of
student from user.
14. temp It is a variable used to enter the name
of student to be updated or deleted.
15. tempst It is a variable used to enter the new
marks of student.
16. sql It is a variable in which we give a
query.
17. execute It is a function used to execute all the
query.
18. commit It is a function used to ends the
connection between python and mysql
till the all queries are run.

97
Session 2023 -24

19. fetchall() It is a function used to print all the


rows.
20. Ans It is a variable used to choice of user to
update the data.
21. ch It is a variable to input the choice of
user from 1 to 5.

98

You might also like