0% found this document useful (0 votes)
39 views32 pages

Adobe Scan Jan 11, 2024

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
0% found this document useful (0 votes)
39 views32 pages

Adobe Scan Jan 11, 2024

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
You are on page 1/ 32
Experiment No: 1 Program 1: Input any number from user and calculate factorial of a number # Program to calculate factorial of entered number num = int(input("Enter any number :"}) fact n=num # storing num in n for printing while num>1 # loop to iterate from n to 2 fact = fact * num num-=1 print('Factorial of", n., ° is :",fact) OUTPUT Enter any number :6 Factorial of 6 is : 720 Date Experiment No:2 Program 1: Input any number from user and check it is Prime no. or not #Program to input any number from user #Check it is Prime number of not import math pum = int(input(” any number :")) isPrimi for { in range(2,int(math.sqrt(num)}+ 1) if num % i == 0 isPrime=False if isPrime: print("@# Number is Prime ##") else: print('## Number is not Prime ##") OUTPUT Enter any number :117 ## Number is not Prime ## Enter any number :119 ## Number is not Prime ## Enter any number :113 ## Number is Prime ## er any number :7 ## Number is Prime #9 Enter any number :19 ## Number is Prime ## Program ; Write a program to find sum of elements of List recursively #Program to find sum of elements of list recursively def findSum(Ist,vum): if num==0 return 0 else return Ist{num-1]+findSum(lst mylist * || # Empty List #Loop to input in list num = int(input("Enter how many number :")) for i in range(num): n = int(input("Enter Element "+str{it 1)+":")) mylist.append(n) #Adding number to list sum = findSum(mylist,len(mylist)) print(‘Sum of List items ",mylist, ° is :’,sum) OUTPUT Enter how many number :6 Enter Element 1:10 Enter Element 2:20 Enter Element 3:30 Enter Element 4:40 Enter Element 5:50 tnter Element 6:60 st items [10, 20, 30, 40, 50, 60} is : 210 me Program 1: Write a program to calculate the n% term of Fibonacel seri: #Program to find 'n'th term of fibonacci series # Fibonacci series : 0,1,1,2,3,5,8,13,21,34,55,89,, fnth term will be counted from 1 not 0 def nthfiboterm{n) ifne=1 return n return (nthfiboterm(n-1)+nthfiboterm(n-2}) ruin = int{input("Enter the ‘n’ term to find in fibonacei :) term =nthfiboterm(num) print(num,th term of fibonacei series is :’,term) OUTPUT _ Enter the ‘n’ term to find in fibonacci :10 10 th term of fibonacci series is ; 5S Date Experiment No: 5 ] Program : Program to search any word in given string/sentence #Program to find the occurence of any word in a string def countWord(str1 word) s = strl.split() count=0 for w in s; if weeword; countt=1 return count irl = input("Enter any sentence :") word = input("Enter word to search in sentence: count = countWord(strl ,ward) if count==0 rint('## Sorry! ",word,” not present ') else: print("## ";word," occurs ",count," times ## ") OUTPU Enter any sentence :my computer your computer our compliter everyanes computer Enter word to search in sentence ‘compute #@ computer accurs 4 times ## Enter any sentence :learning python is fun Enter word to search in sentence ## Sorry! java not present Date Experiment No: 6 Program 1: Program to read and display file content line by line with each word separated by ‘4’ #Program to read content of file line by line #and display each word separated by "# f= open(‘file}.txt") for line in f words = line.split() for win words priniw+' \end=") print() fclose() NOTE : if the original content of file is: India is my country Jlove python Python learning is fun OUTPUT _ India#is#my#country# IWlove#python# Python#learning#is#fun# seriment No: 7 Program 1; Program to read the content of file and display the total number of consonants, uppercase, vowels and lower case characters’ #Program to read content of file and display total number of vowels, consonants, lowercase and uppercase characters f= open(‘filel txt") ve 0 uso 0 o-0 data = f.reado vowels=['a"/e",i'/0"/' for ch in dis if ch.isalphag) if ch tower) in vowels: veel elne ett if ch.iaupper() url elif ch.islower() I+} elif chl='' and chl='\n' tel Total Vowels in file v) Total Consonants in file in :",¢) Total Capital letters in file a) Total Small letters in file") Total Other than letters 0) fclose() NOTE ; if the original content of file is: India is my country Hove python Python learning is fun 123@ OUTPUT Total Vowels in file Total Consonants in file 1 Total Capital tetera in file Total Small letters in file Total Other than letters Program 1: Program to create binary file to store Rolino and Name, Search any Rolino and display name if Roltno found otherwise “Rolino not found” #Program to create a binary file to store Rollno and name WSearch for Rollno and display record if found Hotherwise "Roll no. not found import pickle student=[) f 30 ==> *** QUEUE DEMONSTRATION ™ ENQUEUE DEQUEUE PEE! SHOW QUEUE EXIT Enter your choice :0 Bye Program 1; Program to take 10 sample phishing email, and find the most common word occurring #Program to take 10 sample phishing mail #and count the most commonly occuring word phishingemail=| "jackpotwindlottery.com “[email protected]' "“[email protected]”, "[email protected] "spinthewheelailipkart.com "[email protected][email protected] "[email protected]’ ‘[email protected]’ ‘[email protected]’ | myd={} for ¢ in phishingemail: x=e.split(@) for w in x if w not in myd: mydiw else: mydjw}+=1 key_max = max(myd,key=myd.get) print('Most Common Occuring word is :",key_max) OUTPUT _ ‘Most Common Occuring word is : mymoney.com —————————————————————————————————— Date Experiment No: 16 Program 1: Program to create 21 Stick Game so that computer always wins Rule of Game (Ta 1) User and Computer both can pick stick one by one 2) Maximum stick both can pick in 4 ie, 1 to 4 3) Anyone with last stick will be the looser def PrintStickin) print("o "*n) print("| "*n) print{"| “*n) print("| "*n) print("| “*n) TotalStick-21 win-False humanPlayer=True print Welcome To Stick Picking Game :: Computer Vs User ) print{"Rule: 1) Both User and Computer can pick sticks between 1 to 4 at a time") Print{’ 2) Whosoever picks the last stick will be the looser”) print( Lets Begin ======") playerName = input{"Enter Your Name :") userPick=0 PrintStick(TotalStick) while win==False: if humanPlayer==True: print("You Can Pick stick between 1 to 4") userPick=0 while userPick<=0 or userPick>4: userPick ~ int(input(playerName +": Enter Number af Stick to Pick”)) TotalStick=TotalStick - userPick humanPlayer-False PrintStick(TotalStick) print(*"*60) input(Press any key...") computerPick = (5-userPick) print(’Computer Picks : ";computerPick,” Sticks ") TotalStick=TotalStick -computerPick PrintStick(Total if TotalStick==1 print("## WINNER : COMPUTER ##”) win=True print("*"*60) input(Press any key...") humanPlayer=True —_—_—____SSSSSSS====5 OUTPUT _ === Welcame To Stick Picking Game :: Computer Vs User = Rule; 1) Both User and Computer can pick sticks between 1 to 4 ata time 2) Whosoever picks the last stick will be the looser Enter Your Name :RAJ VHtitt ial 1 | I Hrintiyy HIIElttl HEH PELLET 1 Can Pick stick between 1 to 4 J: Enter Number of Stick ta Pick3 EPP tbr tered FIPPEEELPet tere PITEETTTEEitttel LULL Press any key Computer Picks | 2 Sticks PEPE Pert bree Pride V1 Priya it Wy i Press any key You Can Pick stick between 1 to4 RAd: Enter Number of Stick to Pick Press any keey Computer Picks : 1 Sticks rei reid rei Hi You Can Pick stick between 1 to 4 RAJ: Enter Number of Stick to Pick HrEdt died Hhidttied HEPEn itl PPErneel Press any key Computer Picks a I tI i You Can Pick stick between 1 to 4 RAJ: Enter Number of Stick to Pick3 ' | | Press any key Computer Picks ; 2 COMPUTER ## Program 1: Program to connect with database and store record of emplayee and display records, import ry eayCOn 127.0.0.1' user=root’ password="adi eur = con.cursor() cur.execute("create database if not exists company) eur exectite("use company’) cur execute("create tuble if not exists employee(empno int, name yarchar(20), dept varchar(20),salary int)") con.commith) choice=None while choice!~0 print("1, ADD RECORD ") print("2, DISPLAY RECORD ") print((0. EXIT) choice = intfmput("Enter Choice :")) if choice == 1 ¢ = int(input("Enter Employee Number n= input("Enter Name *") input("Enter Department :*) 3 = intfinput("Enter Salary =) query="insert into employee values( cur.execute(query) con.commit) print("## Data Saved #0") lif choice == 2 query="select * from employee cur.execute(query) result = cur.fetchall) print("%ol Ox"%6" EMPNO”,"%203"%0" NAME" ,"% 159°%" DEPARTMENT 108"96"SALARY) for row in result print("%108"%row[0) ,"%208"%row]1],"%1 S8"%orow[2],"% 108" %row]3}) clif choice=-0 con.close() print('## Byell #6") else print("## INVALID CHOICE ##°) 1. ADD RECORD 2. DISPLAY RECORD 0. EXIT Enter Choice :1 Enter Employee Number :1 Enter Name :AMIT Enter Department :SALES Enter Salary :9000 ## Data Saved ## 1. ADD RECORD 2, DISPLAY RECORD IT Enter Choice :1 1 employee Number :2 Name :NITIN Department :IT ry :80000 aved Hi 1, ADD RECORD 2, DISPLAY RECORD 0, EXIT Enter Choice :2 EMPNO NAME DEPARTMENT SALARY 1 AMIT SALE 9000 2 NITIN Ir 80000 ADD R “ORD 1H Byel! ## periment No: 18 Program 1: Program to connect with database and search employee number in table employee and display recerd, f empno not found display| appropriate message. import mysql.connector ax mycon con = mycon.cannect(hout="127.0.0.1' user='root’,password="adimin database="company’) cur = con.cursor() print("#""40) print(’EMPLOYEE SEARCHING FORM’) print{""*40) print("\n\n') while ans.lower()==V’ eno = int{input(“ENTER EMPNO TO SEARCH :" query="select * from employee where empno={".format(eno} cur.execute(query} result = cur.fetchalll) if cur.roweount=*0: print("Sorry! Empno not found ") (0x"%"EMPNO", “%208"%" NAME", “Yo1 5a"%" DEPARTMENT SALARY") for row in result print("%610s"%rew{0}," ; ow|2],"%108"%row3}) ans=input("SEARCH MORE (¥) :’) OUTPUT HHMONNTANnHMHHERA HeMHanAnOdaHONeNAnanAR EMPLOYEE SEARCHING FORM HHAMNAEAHHNNOONERHHNORNAMNEHUROUEHHBNHER ENTER EMPNO TO SEARCH :1 EMPNO NAME DEPARTMENT SALARY AMIT SALES 9000 SEARCH MORE (¥) sy ENTER EMPNO TO SEARCH :2 EMPNO NAME DEPARTMENT SALARY 2 nrrin rr 80000 SEARCH MORE (¥) -y ENTER EMPNO TO SEARCH :4 Sorry! Empno not found SEARCH MORE (¥) :1 Program 1: Program to connect with database and update the employee record of entered empno. ort mysql.connector as mycon con = mycon,connect(host='127,0.0.1' ,user='root’ password="4 database="company’) cur = con.cursor{} print('#"*40) print((EMPLOYEE UPDATION FORM’) print("#"*40) Print(’\n\n’) y while ans.lower(}=='y eno = int(input("ENTER EMPNO TO UPDATE :*)) query="select * from employee where cur.execute(query) result = cur.fetchall() if curroweount=«( print("Sorry! Empno not found ") pno=f}".format{eno) print("%108"%"EMPNO","%208"%"NAME: 1°" DEPARTMENT 108°%6" SALARY") for row in result Brint("% 108"%row{0} "96208 "%row4 1] choice=input("\n## ARE YOUR SURE TO UPDA‘ if choice lower(}=='y print("== YOU CAN UPDATE ONLY DEPT AND SALARY print("== FOR EMPNO AND NAME CONTACT ADMIN ==") @~ input? ENTER NEW DEPARTMENT (LEAVE BLANK IF NOT WANT 1,°% 108"%row 3h) TO CHANGE J) ifd= d=row{2} ty 5 = int(input(ENTER NEW SALARY,(LEAVE BLAN WANT TO CHANGE ) *)) except s=row/3} query~"update employee set dept='j',salary=i} where empno={ format (d.n,eno) cur.execute(query) con.commnit() print(“## RECORD UPDATED #0 ") ans=input((UPDATE MORE (¥) :") TTTLLELLEEL aeae Lee LLLLLL MPLOYEE UPDATION FORM annawanunenane dunnnoneunenneens ENTER EMPNO TO UPDATE :2 MPNO. NAME DEPARTMENT SALARY 2 NITIN rr 90000 ## ARE YOUR SURE TO UPDATE ? (¥) y == YOU CAN UPDATE ONLY DEPT AND SALARY = == FOR EMPNO AND NAME CONTACT ADMIN ~ ENTER NEW DEPARTMENT (LEAVE BLANK IF NOT WANT TO CHANGE ) ENTER NEW SALARY (LEAVE BLANK IF NOT WANT TO CHANGE } ## RECORD UPDATED UPDATE MORE (Y) :y ENTER EMPNO TO UPDATE EMPNO NAME DEPARTMENT SALARY 2 NITIN ir 90000 ## ARE YOUR SURE TO UPDATE ? (¥) :y == YOU CAN UPDATE ONLY DEPT AND SALARY == FOR EMPNO AND NAME CONTACT ADMIN ENTER NEW DEPARTMENT (LEAVE BLANK IF NOT WANT TO CHANGE jSAL ENTER NEW SALARY (LEAVE BLANK IF NOT WANT TO CHANGE | ## RECORD UPDATED ## UPDATE MORE (Y) :¥ ENTER EMPNO TO UPDATE :2 NAME DEPARTMENT SALARY 2 NITIN SALES 90000 ## ARE YOUR SURE TO UPDATE ? (¥) :¥ == YOU CAN UPDATE ONLY DEPT AND SALARY = == FOR EMPNO AND NAME CONTACT ADMIN « ENTER NEW DEPARTMENT (LEAVE BLANK IF NOT WANT TO CHANGE ) ENTER NEW SALARY (LEAVE BLANK IF NOT WANT TO CHANGE ## RECORD UPDATED ## UPDATE MORE (¥) -¥ PNO TO UPDATE :2 NAME DEPARTMENT SALARY TIN si 91000 ## ARE YOUR SURE TO UPDATE ? (¥) :N MORE (¥) -N Program 1: Program to connect with database and delete the record of| ‘entered employee number. import mysql.connector ax mycon con = mycan.connect(host~'127.0.0. 1 trser d company") cur = con.cursor(} print("#"*40) print("EMPLOYEE DELETION FORM) print(“#"*40) print(’\n\n") root’, password="admin’ ans.lower()==\y eno = int(input("ENTER EMPNO TO DELETE :)) query="select * from employee where empno=f)’forn cur.execute(query) resuilt = cur,fetchall}) if cur.roweount==0; print{"Sorry! Empno not found ») else print("%108"%" EMPNO”,"%208"96" NAME TMENT" 108"96” SALARY’) for row in result print("%10s"%row{0},"%20s"%row{1] row{2],"%108"%4rew!3)) choice=input(" \n## ARE YOUR SURE TO DELETE ? (¥) :) if choice lower(}=~'y query='delete from employee where empn: cur.execute(query) con,commit() print('="+ RECORD DELETED SUCCESSFULLY! ===") minput(DELETE MORE ? (¥) >) OUTPUT NUHHOERR EERE HEHHENOHUNNNNHROHEMEHR ERE EMPLOYEE DELETION FORM NONNEMEEEOMAIHERIMNHHRI OHM OR AMeRHOHEH (eno) ENTER EMPNO TO DELETE EMPNO NAME DEPARTMENT SALARY 2 NITIN SALES 91000 W ARE YOUR SURE TO DELETE ? (Y)-y “= RECORD DELETED SUCCESSFULLY! DELETE MORE ? (¥) vy ENTER EMPNO TO DELETE Sorry! Empno not found DELETE MORE ? (Y) in

You might also like