Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
47 views
Python Practical File MySql + Python 25 Python Programs + SQL Commands
Uploaded by
cgaur03032006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Python Practical File MySql + Python 25 Python Pro... For Later
Download
Save
Save Python Practical File MySql + Python 25 Python Pro... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
47 views
Python Practical File MySql + Python 25 Python Programs + SQL Commands
Uploaded by
cgaur03032006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Python Practical File MySql + Python 25 Python Pro... For Later
Carousel Previous
Carousel Next
Download
Save
Save Python Practical File MySql + Python 25 Python Pro... For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 44
Search
Fullscreen
INDEX : Teacher's S.No Program Title Date : Sign 1 | SQLCommands 4/5/2020 2 | To input principal amount, rate and time 10/5/2020 and calculate simple interest. 3 | To input a number and print its factorial. | 12/5/2020 a To input a number and check whether 14/5/2020 prime or not. To print the multiplication table of a 2 number entered by the user. 16/5/2020 To display the Fibonacci sequence up to 6 | n-th term where n is provided by the 18/5/2020 user. 7 To input a number and check if it is 20/5/2020 Armstrong number or not. 8 To count the number of each vowel in a 22/5/2020 string and display it.To show output- . 1\n22\n333\n4444\n55555. 24/5/2020 To find those numbers which are 10 | divisible by 7 and multiple of 5, between | 26/5/2020 1500 and 2700 (both included). uw To accept a word from the user and 28/5/2020 reverse it. Write a function to count the number of 12 | lines in text file "story.txt" which is 27/7/2020 starting with an alphabet "A". To read a .txt file and print only the i number/digits from this file. 29/7/2020 4 de print just the last line of text file 31/7/2020 ‘story.txt". To count the number of lines in 15 | "poem.txt" that begins from uppercase 2/8/2020 characters. To create a function that takes a number 16 | as parameter and checks whether the 4/8/2020 number is prime or not. To create a function that takes a no as 17 | parameter and checks whether it is 6/8/2020 Armstrong number or not.To create a .csv file & update it with 18 | records of 5 students & their roll nos, 10/8/2020 names & marks, then print the file. 19 Create a function that linearly searches 24/10/2020 for an element in an array. 20 To create a function that binary searches 26/10/2020 for an element in an array. 21 | To insert an element in a sorted array. 28/10/2020 2 To delete an element from a sorted 30/10/2020 array. WAP to implement various stack = functions in Python. 1/11/2020 WAP to display first three rows fetched 24 | from student table of MySQL database | 12/12/2020 “test”. WAP to display first three rows fetched 25 | from student table of MySQL database | 14/12/2020 “test”. Use pymysql.SQL Commands Do the following question on computer by creating the required tables in SQL Software: Table: PRODUCT PID ProductName Manufacturer Price TPO1 Talcom Powder LAK 40 FWO05 Face Wash ABC 45 BSO1 Bath Soap ABC 55 SH06 Shampoo XYZ 120 FW12 Face Wash XYZ 95 Table: CLIENT CID ClientName City PID 01 Cosmetic Shop Delhi FW05 06 Total Health Mumbai BSOL 12 Live Life Delhi SH06 15 Pretty Woman Delhi FW12 16 Dreams Banglore TPOI1. To create table PRODUCT & CLIENT. mmmand Line Client Gl Mysal 2.0 Cor Dares varchar eg3. To insert the records in the above tables. BB MySQL 8.0 Command Line Client4. To view the contents of the tables. (BB MySQL 8.0 Command Line Client oan 5. To display city (no duplicate values). (BB MySQL 8.0 Command Line Client6. To display the contents of PRODUCT table having Manufacturer as XYZ. { MySQL 8.0 Command Line Client 7. To display the ClientName in descending order. | EB MySQL 8.0 Command Line Client 8. To change the value of ClientName — Dreams to DreamWorld. GB MySQL 8.0 Command Line Client9. To increase the price of Talcom Powder by 25. (I MySQL 8.0 Command Line Client 10. To display the record having maximum Price value. El MySQL 8.0 Command Line Client from product 11. To display number of Manufacturers along with their count. | EE MySQL 8.0 Command Line Client12. To display the Cartesian product of both the tables. ‘ommand Line Client 13. To display ClientName & ProductName having same P_ID.14. To delete the content of table having price less than 50. GBB MySQL 8.0 Command Line ClientPython Scripts Program 1 Question: To input principal amount, rate and time and calculate the simple interest. Program Code: [B Program 22;py- E\Lakshya\ Computer HW\Program 29py (3.73), eee Gee Eile Edit Format Bun Options Window Help #To input principal amount, rate and time and calculate the simple interest. sb (Anput ("Enter Principal Amount: ")) Output: [GB Python 3:73 shen arc | Ble Eat shell Debug Options Window Help Fython 3.7.3 (v3.7.3:efdecéedl2, Mar 25 2018, 22:22:05) [MSC v.1916 64 bit (AMD6 4)) on wins2 Type "hep", "copyright", "credits" or "license()" for more information. vem RESTART: E:\Lakshya\Computer HW\Program 29.py “=== Enter Principal Amount: 10000 Enter Rate (% per annum): 10 Enter Time (years So aProgram 2 Question: To input a number and print the factorial of the number. Program Code: | UB “Program 30,py -EA\Lakshya\Computer HW\Program 30,py(3.7.3)" - 2 s | Ele fait Format _Bun Qptions Window Help ‘#7o input a number and print the factorial of the number. ”» neint (input ("Enter 2 nunbe: bel for a in range(1, ntl): btza print ("The factorial of", n, "is", b) Outpu' UB Python 373 Shen Sees le_Edit_ Shell Debug Qptions Window Help Fython 3.7.3 (v3.7.3:efecéedl2, Mar 28 2018, 227 4)] on wins2 Type "help, "copyright", "credits" or "license()" for more information. 708) [MSC v.1516 64 bit (AMDE RESTART: :\Lakshya\Computer HW\Program 30.py Enter @ number: 8 The factorial of 8 is 40320 RESTART: Enter a number: 7 The factorial of 7 is 5040 :\Lakshya\Computer HW\Program 30.py =Program 3 Question: To input a no and check whether prime or not. Program Code: [(@ Program 31py - E\Lakshya\ Computer HWAProgeam 3.py 73) - Oo x Ble _féit Format Bun Qptions Window Help ‘#To anput a no and cheeck whether prime or not. ne int (input ("Enter @ number: ")) bo for a in range(2, n): Sf ntaneo: bend Af ear Print(n, "is not prame.") else: print(n, "is prime.*) Output: UB Python 373 Shen as Ele Edit Shell Debug Options Window Help Python 3.7.3 (v3.7.3:efecéedl2, Mar 25 2018, 22:22:08) [NSC v.1916 64 bie (AMDG 4)) on win32 Type "help", "copyright", "credits" or "License()" for more information. >>> RESTART: E:\Lakshya\Computer #W\Program 31.py Enter @ number: 5 5 is prime. RESTART: E:\Lakshya\Computer HW\Program 31.py a7 Enter a number 27 4s not prime. sesneeceacaaaes RESTART: E:\Lakshya\Computer HW\Frogram 31.py Enter @ number: 31 31 48 prime.Program 4 Question: To print the multiplication table of a no. entered by user. Program Code: a Program 32py-E\Lakehye Computer HIM Program 32,9 3.73) Saas | ile Est Format Run Options Mindow Help ‘¥To print the multiplication table of a no entered by the u neint (input ("Enter a number: ")) print ("The multiplication table of",n, "is: for ain range(1, 11): penta print (n,"*",a,"=",b) Output: [0B Pytnon 373 Shen Sor File Edit Shell Debug Options Window Help Python 3.7.3 (v3.7-Srettectedl2, Mar 25 2018, 22:22:08) MBC v.181é €4 bie (Ne 2) on wins Type thelp", "copyright", "credits" or "license ()* for more information, Restart: :\Lakshya\Computer HW\Program 32.py eisai azt2=24 12 *3=36 wtasae a2 * 5 = 60 te=72 7-84 + e=96 12 * 9 = 108 12 * 10 = 120Program 5 Question: To display the Fibonacci sequence up to n-th term where n is provided by the user. Program Code: a Program 33py-E\lakehye Computer HIM Program 33.9y 3.73) - ao x Fle fit Format__Bun Options Window Help ‘To display the Fibonacci sequence up to n-th term where n is provided by the fuser. ano be craeb n=int (input ("Enter the number of terms you wish to see: ")) print (a, by sep=",",end for d in range(0y print (c,end="") ab bee crash Sf die print (",",ende" Output: (B Python 3.73 She See | fle fait Shell Debug Options Window Help Python 3.7.3 (v3.7.3:efdecéedl2, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMDE 4)] on wins2 Type "help", "copyright", "credite” or "License ()" for more information. RESTART: E:\Lakshya\Computer HW\Program 33.py <== Enter the number of terms you wish to see: & 0,14123+548413 peennnnnnnnnnn= RESTART: Enter the number of terms you wish to see: 12 0, 141+2¢375,8/13,21, 34, 55,89Program 6 Question: To input a no and check if it is Armstrong no. or not. Program Code: LB Program 3épy-E\Lakahye Computer HIM Program 349y 3.73) = oaaeex Bile Edit Farmat Run Qptions Window Help ‘¥o input a no and check whether it is an mmatrong AO OF not. nt (input ("Enter a number: ")) enetz(n) au-0 for ain st bint (a) babes, as nee Print ("Yes,", n, "is an Armstrong number.") elser print ("o,", n, "1s not an Armstrong numbe: Output: (B Python 3.73 Shell rela Ble Edit Shell Debug Options Window Help Python 3.7.3 (v3.7.3:efsecéedlz, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AHDE 4)) on win32 Type "help", "copyright", "credits" or "license()" for more information. = RESTART: E:\Lakshya\Computer #W\Program 34.py Enter a number: 153 Yes, 153 is an Armstrong number. RESTART: Enter a number: 66 No, 66 42 not an Armstrong number. \takshya\Computer HW\Program 34-pyProgram 7 Question: To count the number of each vowel in a string and display it. Program Code: [i Program 35;py - E\Lakshye\Computer HW\Progrem 35py (3.73) =x ile eit Format un Options Window Help #To count the number of each vowel in a string and display it. srinput ("Enter a string: ") nano neo no=0 for a ina Af acstat or asta nas=1 eis a ster or amerets san elds g sera! of amerrts nase, eas @ seto! oF ametors lig a stat or ametuts print ("Amount of the vowel ‘at in string na) Brant ("Amount of the vowel string ne) print ("Amount of the vowel 'i' in string Print ("Amount of the vowel 'o' in string Prant ("Amount of the vowel 'a' in string ma) no) zu) Output: Python 3.7.3 (v3.7.3:eféecéedi2, Mar 25 2018, 22:22:08) [MSC v.1916 64 bic (AMDE 4)) on win32 Type "help", "copyright", "credits" or "license()" for more information. RESTART: E:\Lakshya\Computer HW\Program 35-py Worm is a webserial owned by Wildbow. Please support the officia Enter a atrins 1 release. Amount of the vowel ‘a’ sn string 49 Amount of the vowel 'e' in string is Amount of the vowel 'i' in string 13 Amount of the vowel 'o' in string is Amount of the vowel ‘ut in string isProgram 8 Question: To show output 1\n22\n333\n4444\n55555. Program Code: LB Program 36py-E\lakehye\Computer HIM Program 3539y 2.73) Shox | Ble Est Famst Bun Options Window Help ¥Fo display output? 1\n22\n333\n4444\nSS555. for a in range(1, 6 for b in range (0,a print (a, end print() Outpu' [& Python 3.73 Shell Soe eae File Edit Shell Debug Options Window Help Python 3.7.3 (v3,7.3:ef4ecéedi2, Mar 28 2018, 22:22:08) [MSC v.1816 64 bit (MDE 4)) on wins2 fe "help", "copyright", "credite" or "license()" for more information. wnone= RESTART: :\Lakshya\Computer HW\Program 36.py —Program 9 Question: To find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700 (both included). Program Code: LB Program 37py-E\lskehye\Computer HWM Program 3739y 2.73) - o x File fit Format Bun Options Window Help ¥fo find those nunbers which are divisible by 7 and multiple of 5, between 1500Output: UB Python 373 shet - File Edit Shell Debug Options Window Help 4)) on wins? Type "help", "copyright", "credits" or "license()" for more information. RESTART: E:\Lekshya\Computer HW\Progrem 37-py 1505 1540 1575 i610 1685 1680 478 1750 ames 1820 ess 1880 1925 1960 1995, 2030 2065 2100 2138 2170 2208 2240 2275 2310 2345 2380 2418 2450 2408 2520 2555 2590 2628 2660 2688Program 10 Question: To accept a word from the user and reverse it. Program Cod: (B Program 38.py - E\Lakshya\ Computer HW\Program 38py (3.73) ates File Edit Format Run Options Window Help ‘To accept a word from the user and reverse it. srinput ("Enter a string: *) ai~s[t-2] print ("The reverse of '", 9, "! ist sy sep Output: UB Python 373 Shed Sone Eile Edit Shell Debug Options Window Help Fython 3.7.3 (v.7.3tefdecéedi2, Mar 25 2018, 2 4)) on wins2 Type "help", "copyright", "credits" or "license()" for more information. 05) [MSC v.1916 64 bit (AMDE RESTART: E:\Lakshya\computer HW\Program 38-py Enter @ string: I am justice, the harbinger of Seath! Yes, Seath, not Death. The reverse of ‘I am justice, the harbinger of Seath! Yes, Seath, not Death.' is : sBtaeD ton ,htaeS ,se¥ !htaeS fo regnibrah eht ,ecitsuj ma I RESTART: E:\Lakshya\Computer #W\Program 38.py Enter a string: They are two entirely different things. Seath being more terrify ang. The reverse of ‘They are two entirely different things. Seath being more territy ee enn ee ee ee es >>>)Program 11 Question: Write a function to count the no. of lines in text file ‘story.txt’ which is starting with an alphabet ‘A’. Program code: (B Program a7 (Start of Python srpt 6) py-E/Lalehya/Computer HW/Progam47(Star ofPy.. — OX | Ble Est Fame Bun Options Window Help $icicn ia usccion: 20 Coome ‘the wo. GE Les in, pant Gila eooey cae wich Se fecarting dee counta (b) =o Sropenb, "2") or Line to} Print (4) Output: = RESTART: E:/Lakshya/Computer #W/Program 47 (Start of Python scripts 6) .py 4 = RESTART: F:/Lakshya/Computer HW/Program 47 (Start of Python scripts 6) -py 4 Text File: | Dh story - Notepad - o x File Edit Format View Help A test this is. Seeing my Yoda speak, I am. ‘And it was surprisingly good. another test which is to see how no punctuation affects my writing apparently not much how about now now its much worse|Program 12 Question: A text file contains alphanumeric text (in txt file). Write a program that reads this file and prints only the no. or digits from this file. Program code: [a Program 48.py - E/Lakshye/Computer HW/Progrem 48.py (3.7.3) - ao x Bile Edit Format Run Options Window Help ‘¥A text file contains alphanumeric text (in txt file). WAP that reads this file fand prints only the no. or digits from this file. f.close() Output: :/Lakshya/Computer HW/Program 48.py — 3 1 ° e 5 5 5 i Text Fil Di files - Notepad ao File Edit Format View Help Examples of digits in words: Zer@, D3ce1i0n, ASSa5Sin, etc. Examples of normal digits: @,1,2,etc. Examples of letters: a,b,c,etc. Examples of capital letters: A,B,C,etc.|Program 13 Question: Write a program to print just the last line of text file “story.txt”. Program code: | [B Program 4spy -EALakshye\Computer HW\Program 48 py (3.73) - a x Ele Edit Format un Options Window Help WAP to pani en ("etory. zeadlines () print (a{-1]) f.close() Output: = RESTART: E:/Lakshya/Computer HW/Program 49.1.py — now ite much worse Text File: | Gh story - Notepad - o x File Edit Format View Help A test this is. Seeing my Yoda speak, I am. And it was surprisingly good. another test which is to see how no punctuation affects my writing apparently not much how about now now its much worse|Program 14 Question: Write a program to count no. of lines in “poem.txt” that begins from uppercase characters. Program code: (B Program Sopy-E/Lakshye/Computer HW/Progrem 50.py (273) le Feit Format Run Options Window Help SWAP to count no. of lines in “poem.txt” that begins from uppercase characters pen ("poem. txt", "r") sreadlanes() ox bina: if BIO] -Asupper(): cel print (c) £.close() Output: RESTART: E:/Lakshya/Computer #W/Program 50.py Text File: DD poem - Notepad - o x File Edit Format View Help Hold fast to dreams for if dreams die life is a broken-winged bird ‘that cannot fly. Hold fast to dreams for when dreams go life is a barren field frozen with snow.Program 15 Question: Write a program to create a function that takes a number as parameter and check whether the number is prime no. or not. Program code: (B Program 51.py - E/Lakshya/Computer HW/Program SI.py (3.73) Seeclisss $6 File Edit Format Run Options Window Help WAP to create a function that takes a number as parameter and check whether fthe number is prime no. or not. Get pramecheck(a) + Sf acai nt ("Given number is not a prime number") Af asb=0: cH af ome: print ("Given number is 8 prime number." else: int ("Given number is not a prime number.") dint (input ("Enter @ number: ")) primecheck (4) Output: RESTART: Enter @ number: 29 Gaven number is a prime number. /akshya/Computer HW/Program $1.py — RESTART: E:/Lakshya/Computer #W/Program 51.py Enter @ number: 1 Given number is not a prime number. RESTART: E:/Lakshya/Computer HW/Program 51.py = Given number is a prime nunber.Program 16 Question: Write a program to create a function that takes a number as parameter and check whether the number is Armstrong no. or not. Program code: La Program 52 (nd of PSB).py = E/Lakehya/Computer HW/Program 52 (End of PSBL.py 73) a file Edt Famat Bun Options Window Help FWA? co creace a function chat cakes © number as parameter and check whether fene number is Armstrong no. or not. dee Remstrongeneck (a)? print ("Given no 42 not armstrong no.") neint (input ("Enter 2 number: ")) Armstrongcheck (n) Output: RESTART: E:/Lakshya/Computer HW/Program 52 (End of PS6).py Enter @ number: 1 Given no is armstrong no. RESTART: E:/Lakshya/Computer HW/Program 52 (End cf PS6).py Enter a number: 153 Given no 4 armstrong no. RESTART: E:/Lakshya/Computer HW/Program $2 (End of PS6).py Enter a number: 27 Given no is not armstrong no.Program 17 Question: Write a program to create a .csv file and update it with the records of 5 students and their roll no, names and marks. Then print the .csv file. Program code: (B “Program 53 (End of PS7.py -E/Lakshya/Computer HW/Program 33 (End of PSTpy@B73)" — x File Edit Format Bun Options Window Help aR zropen(*Stu.csv™, "w") s.wriverow ([rno,nm, Mrks]) z.close () with open( csv", "x", newLine='\r\n') as Rr Pi Reciese()Output: RESTART: E:/Lakshya/Computer HW/Program 53 (End of P37) .py Seudent record 1 Enter roll no: 1 Enter name: Aryan Enter marks: 70 Student record 2 Enter roll no: 2 Enter nane: Daray Enter marke: 65 Student record 3 Enter roll no: 3 Enter name: Harshir Enter marke: 45 Student record 4 Enter roll no: 4 Enter name: Karan Enter marke: 5S Student record S Enter roll no: § Enter nene: Naresh Enter marke: 95 ('Rolino', ‘Name’, ‘Marks*} (12", ‘Aryan*, *70.0') (12"; ‘Dhruv', 165.0" (43", ‘Harshat*, '45.0") (14", ‘Karan’, *55.0'] ('S', ‘Nazesh', *95.0"] + fice Jens hs - Behe = E> Bowe - A ty thProgram 18 Question: Write a program to create a function that linear searches for an element in an array. Program code: UB Program 58 (str of PSS). py -E/Lakshya/Computer HW/Program 58 (Star of PSB.eyQ73 — O Xx Ele ait Farmet_Bun Options Window Help ‘Finear searching in an array. Gee Lineaz_Seazch (AR, Item) : a0 while 4
>>, RESTART: E:/Lakshya/Computer #W/Program 59.py Enter deaized linear-list size (max 50) 10 Enter elements for linear list in ASCENDING ORDER: Element 0-2 Element 1-2 Element 2=3 Element Element Element Elenent Element Element O99 Element 910 Enter element to be searched fort 11 Sorry! Given element could not be found. :/Lakshya/Computer HW/Program 58.py Enter desired linear-list size (max 50) s Enter elements for Linear 1st in ASCENDING ORDE! Element 0-1 Element Element Element Element 4=9 Enter element to be searched for: S Element found at index: 2, position: 3 Ln20 Cok 0Program 20 Question: Write a program to insert an element ina sorted array. Program code: [2 Program 60.py -E:/Lakshya/Computer HW/Program 60.py (3.73) = oO x Bile Edit Format un Options Window Help ‘inserting an element in a sorted array using traditional algorithm. ef Find Position (AR, Item) t size=len (AR) Af atemcAR(0]: return 0 else: pos=-1 for i in range(size-1): Af AR[A]
=past AR[A]“AR[L-2] sei-l + _main_ Sint (input ("Enter desired linear-list size:\n")) print (*\nEnter elements for linear list in ASCENDING ORDER:\n") array=(0] "2 for 4 in range(n): array[i]=int (input ("Element "+str (3) +" print ("\nThe lier in ascending order £2") print (azzay) dvemeint (input ("\nEnter new element to be inserved:\n")) position-Find Position (array, stem) Shift (array, position) array[position}=item print ("\nThe list after inserting", item,"is:") print (array) » Ln 24 Cok 49)Output: (Python 373 shell - ao x Eile Edit Shell Debug Options Window Help RESTART: E:/Lakshya/Computer HW/Program €0.py Enter desired linear-list size: 4 Enter elements for linear list in ASCENDING ORDER: Element Element Element Element The list in ascending order is: ih air 8) Enter new element to be inserced: iS The list after inserting § 4) By 2, 3 4 51 RESTART: E:/Lakshya/Computer HW/Program 60.py =sssssssceeses= Enter desired linear-list size: 4 Enter elements for linear list in ASCENDING ORDER: Element 0: Element 1: Elenent 2: Element 3: The list in ascending order is: 12, 4, 7% 91 Enter new element to be inserted: fe The list after inserting 6 is: 1s 4p es 7, Ln 140 CokProgram 21 Question: Write a program to delete an element from a sorted array. Program code: [& Program 61.py - E:/Lakshya/Computer HW/Program 61.py (3.73) = Oo x Ble Edit Format fun Options Window Help ‘Deletion of an element from a sorted linear it ef Binary _Seazch (AR, Item): while begclast: mid=(beg+Last) //2 S= Tnem==AR [mia] : en mid elif TeemAR[mid] : begrmid, ele: agt=mid-2 else: return -2 #_main, int (input ("Enter desired linear-liet size:\n")) print ("\nEnter elements for linear list in ASCENDING ORDER:\n") array=[0]*n for 4 in range(a): array[i]=int (input ("Element "+31 print ("\nThe list in sorted order is: print (array) Atem=int (input ("\nEnter element to be deleted:\n")) position=Binary Search (array, item) if position del array[position] print ("\nThe list after deleting", item, "is: print (array) aye"n)) ) else print ("\aSorry! No such element in the list. Lm22 Coto)Output: (Python 373 shell - ao x Eile Edit Shell Debug Options Window Help RESTART: E:/Lakshya/Computer HW/Program €1.py Enter desired linear-list size: 5 Enter elements for linear list in ASCENDING ORDER: Element O2 Element 12 Element 23 Element 34 Element 4=5 The list in sorted order is: Ia, 2 3, 4, 81 Enter element to be deleted: a The list after deleting 2 se: Ti Ae 5] RESTART: E:/Lakshya/Computer #W/Program €1.py Enter desired linear-list size: 4 Enter elements for linear list in ASCENDING ORDE! Element O=2 Element 1=3 Element 2-5 Element 37 The list in sorted order is: i, 316). 31 Enter element to be delet! A Sorry! No such element in the list. Ln CoboProgram 22 Question: Write a program to implement various stack functions in Python. Program code: [Be Program 62 (End of PS8),py - E/Lakshya/Computer HW/Program 62 (Endof PSB.pVG73) — O file Edit Format Bun Options Window Help ‘Fimplementing stack operations. ‘#Scack: implemented as a list top: integer having position of topmost element in Stack def isEmpty (stk): Af stke=[]! return True else: return False def Push (stk, Item): stk. append (Item) top=ien (stk) 2 def Pop(stk)+ Af AsEmpty (atk): return "Underflow" eis Item=stk-pop() AE en(stk)==0: ‘top=None ese topaien (stk)-2. return Item def Peek (stk): Af Asempey (stk) + return "Underflow" else! topelen (stk) -2 seturn stk[top] def Display (stk): Af isEmpty (stk): Print ("Stack empty") else: top=len (stk) -2 print (stk[top],"<-rop") for a in range (top-1,-1,-1)+ print (stk[a]) #_main_ Stack=[] ‘top=iionewhile Tru print ("STACK OPERATIONS") print ("1. Push") print ("2. Pop") print ("3. Peek") print ("4. Display stack") print ("S. Exit") chwint (input ("\nEnter your choice (1-5):\n")) if chi: print () Avemmint (input ("Enter item:\n")) Push (Stack, item) print () elit cheez: print () Avem=Pop (Stack) Af item=="Underflow": print ("Underflow! Stack is empty!") prant () else: print ("Popped item is: print () elif chess: rant () Avem=Peek (Stack) Af dvemeerUnderfiow™: print ("Underflow! Stack is empty!") print () else! print ("Topmost item is print () elif che=4: print() Display (Stack) print () elit chess: break else: print() print ("Invalid choice: print() aver item) Ln 75 CoOutput: [Python 3.73 shell el file_Edit_ Shell Debug Options Window Help seeeesees RESTART: E:/Lakshya/Computer HW/Program €2 (End of PS0).py sseeemee= STACK OPERATIONS + Push Pop Peek Display stack 5. Exit Enter your choice (1-5): € Invalid choice! STACK OPERATIONS + Push Pop Peek Display stack Exit Enter your choice (1-5): a Enter item: a STACK OPERATIONS a. Push 2. Pop 3. Peek 4. Display stack 5. Exit Enter your choice (1-5): 3 Topmost item is: 1 STACK OPERATIONS 1. Push 2. Pop 3. Peek 4. Display stack 5. Exit Enter your choice (1-5): 4 1
You might also like
Computer science class 12th practical file
PDF
No ratings yet
Computer science class 12th practical file
29 pages
cs practical_merged
PDF
No ratings yet
cs practical_merged
51 pages
21Program
PDF
No ratings yet
21Program
21 pages
IPPRACCOVER-1
PDF
No ratings yet
IPPRACCOVER-1
17 pages
Practical File 2023-24
PDF
No ratings yet
Practical File 2023-24
26 pages
Practical2023 24
PDF
No ratings yet
Practical2023 24
16 pages
yadav saar gr 11 cs codes
PDF
No ratings yet
yadav saar gr 11 cs codes
8 pages
class 12 cs project
PDF
No ratings yet
class 12 cs project
32 pages
AI Prasun
PDF
No ratings yet
AI Prasun
12 pages
Program
PDF
No ratings yet
Program
4 pages
Practicals (List Ones Given by Ma'am
PDF
No ratings yet
Practicals (List Ones Given by Ma'am
66 pages
Std-10 AI Python Program
PDF
No ratings yet
Std-10 AI Python Program
13 pages
Python Programming Lab
PDF
No ratings yet
Python Programming Lab
45 pages
12th Practical File 2022-23 All Programs
PDF
No ratings yet
12th Practical File 2022-23 All Programs
19 pages
Computer Science Practical Notes
PDF
No ratings yet
Computer Science Practical Notes
35 pages
Alpine - Cs - 12
PDF
No ratings yet
Alpine - Cs - 12
51 pages
PDF 25:12:2023 15:00:57-1
PDF
No ratings yet
PDF 25:12:2023 15:00:57-1
35 pages
Aim: Programming in Python
PDF
No ratings yet
Aim: Programming in Python
8 pages
Hands On Practice
PDF
No ratings yet
Hands On Practice
114 pages
Python NMFS
PDF
No ratings yet
Python NMFS
6 pages
Cs Pratical Codes (Final)
PDF
No ratings yet
Cs Pratical Codes (Final)
73 pages
practical cs.pdf
PDF
No ratings yet
practical cs.pdf
19 pages
Prac Format 24 - 25
PDF
No ratings yet
Prac Format 24 - 25
23 pages
Cs Practical Revised - Copy
PDF
No ratings yet
Cs Practical Revised - Copy
50 pages
CS PRACTICAL FILE
PDF
No ratings yet
CS PRACTICAL FILE
46 pages
Computer Science
PDF
No ratings yet
Computer Science
33 pages
Practical cs
PDF
No ratings yet
Practical cs
18 pages
Practical 2
PDF
No ratings yet
Practical 2
23 pages
Assign 12th
PDF
No ratings yet
Assign 12th
14 pages
Lab Manual Programs
PDF
No ratings yet
Lab Manual Programs
32 pages
Practical File 2023-2024 Final
PDF
No ratings yet
Practical File 2023-2024 Final
31 pages
Computer Science Program File
PDF
No ratings yet
Computer Science Program File
41 pages
Program 20: Perform All The Operations With Reference To Table Employee' Through Mysql-Python Connectivity
PDF
No ratings yet
Program 20: Perform All The Operations With Reference To Table Employee' Through Mysql-Python Connectivity
40 pages
CS Practical File
PDF
No ratings yet
CS Practical File
47 pages
Python Rec 71762231001
PDF
No ratings yet
Python Rec 71762231001
68 pages
Python Learinng Material
PDF
No ratings yet
Python Learinng Material
94 pages
XII STD CS PRACTICAL MANUAL (1)
PDF
No ratings yet
XII STD CS PRACTICAL MANUAL (1)
12 pages
Report File 12
PDF
No ratings yet
Report File 12
33 pages
12 cs practical file 2024-25
PDF
No ratings yet
12 cs practical file 2024-25
47 pages
Python Lab Manual
PDF
No ratings yet
Python Lab Manual
8 pages
Final Python Journal 112
PDF
No ratings yet
Final Python Journal 112
51 pages
CLASS-X PRACTICALS FOR SESSION 2024-25-FILE-1 (1 TO 15)
PDF
No ratings yet
CLASS-X PRACTICALS FOR SESSION 2024-25-FILE-1 (1 TO 15)
6 pages
Anurag.python
PDF
No ratings yet
Anurag.python
69 pages
Python Vishal
PDF
No ratings yet
Python Vishal
27 pages
Class 12th Activity File Computer Science New
PDF
100% (1)
Class 12th Activity File Computer Science New
32 pages
CSC_XII_Practicalfile_2024_2025.docx
PDF
No ratings yet
CSC_XII_Practicalfile_2024_2025.docx
52 pages
Python Workbook
PDF
No ratings yet
Python Workbook
24 pages
Ais Cs 2021-22 Praclist
PDF
No ratings yet
Ais Cs 2021-22 Praclist
7 pages
PYTHON PROGRAMMING LAB ASSIGNMENTS Final (1)
PDF
No ratings yet
PYTHON PROGRAMMING LAB ASSIGNMENTS Final (1)
31 pages
X Ai Practicals 2023-24
PDF
No ratings yet
X Ai Practicals 2023-24
6 pages
Python Exercise-5
PDF
No ratings yet
Python Exercise-5
19 pages
Class 8-1
PDF
No ratings yet
Class 8-1
9 pages
Python Programs
PDF
No ratings yet
Python Programs
10 pages
Computer Science 2
PDF
No ratings yet
Computer Science 2
22 pages
Practical File 2024-25
PDF
No ratings yet
Practical File 2024-25
71 pages
Screenshot 2024-12-16 at 7.02.10 PM
PDF
No ratings yet
Screenshot 2024-12-16 at 7.02.10 PM
38 pages
XII CS PRACTICAL FILE 25-26
PDF
No ratings yet
XII CS PRACTICAL FILE 25-26
43 pages
cs practical file
PDF
No ratings yet
cs practical file
18 pages