ar
Feedback
CBSE COMPUTER SCIENCE

CBSE COMPUTER SCIENCE

الذهاب إلى القناة على Telegram

QUESTION BANK, REFERENCE BOOK, LAB MANUAL , WORKSHEET ETC., PYTHON TEXT BOOK AND REFERENCE BOOKS, 01. ASK QUESTIONS AT https://t.me/joinchat/FJ1noGs-64I0OWI1

إظهار المزيد
549
المشتركون
لا توجد بيانات24 ساعات
لا توجد بيانات7 أيام
لا توجد بيانات30 أيام
أرشيف المشاركات
#Program to read content of file line by line #and display each word separated by '#' f = open("file1.txt") for line in f: words = line.split() for w in words: print(w+'#',end='') print() f.close()

# To find Fibonacci series : 0,1,1,2,3,5,8,13,... as a LIST Object def fibo(num): a=0 b=1 fib=[a,b] for i in range(3,num+1): c=a+b fib.append(c) a=b b=c return fib num = int(input("How many terms? ")) print("Fibonacci Series : ",fibo(num))

#Program to find the occurence of any word in a string def countWord(str1,word): s = str1.split() count=0 for w in s: if w==word: count+=1 return count str1 = input("Enter any sentence :") word = input("Enter word to search in sentence :") count = countWord(str1,word) if count==0: print("## Sorry! ",word," not present ") else: print("## ",word," occurs ",count," times ## ")

#Program to find sum of elements of list recursively def findSum(lst,num): if num==0: return 0 else: return lst[num-1]+findSum(lst,num-1) 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(i+1)+":")) mylist.append(n) #Adding number to list sum = findSum(mylist,len(mylist)) print("Sum of List items ",mylist, " is :",sum)

# PROGRAM 3 import math def palindrome(s): rev = s[::-1] if(rev == s): print("The string is palindrome") else: print("The string is not a palindrome") def countc(s,c): c = s.count(c) return c def replacec(s,i): c = s[i] nc = input("Enter the character to replace :") if(len(nc)==1): ns = s.replace(c,nc) print(ns) return ns else: print("Enter only one character") while(1): print(" Menu") print("1. Palindrome") print("2. Number of Occurence") print("3. Replace character") print("4. Exit") ch = int(input("Enter your choice:")) if(ch==1): s = input("Enter the string :") palindrome(s) elif(ch==2): s = input("Enter the string :") c = input("Enter a character :") if(len(c)==1): print("The character ",c," is in ",s, ",", countc(s,c), " times") else: print("Enter only one character") elif (ch==3): s = input("Enter the string :") i = int(input("Enter an index :")) print("The string after replacement is :",replacec(s,i)) elif(ch==4): break else: print("Wrong Choice")

# PROGRAM 2 import math def tarea(b,h): a = 0.5 * b * h return a def carea(r): a = math.pi * r *r return a def rarea(n,s): a = (s * s * n) / ( 4 * math.tan(180/n)) return a while(1): print(" Menu") print("1. Area of Triangle") print("2. Area of Circle") print("3. Area of Regular polygon") print("4. Exit") ch = int(input("Enter your choice:")) if(ch==1): b = float(input("Enter the base of triangle : ")) h = float(input("Enter the height of triangle : ")) print("The area of triangle : ",tarea(b,h)) elif(ch==2): r = float(input("Enter the radius of circle :")) print("The area of circle :",carea(r)) elif (ch==3): n= int(input("Enter the number of sides")) s = float(input("Enter the dimension of side")) print("The area of the polygon :",rarea(n,s)) elif(ch==4): break else: print("Wrong Choice")

# PROGRAM 1 def series1(n): init1 = 8 init2 = 7 print(init1) print(init2) for i in range(3,n+1): if(i%2==1): init1 = init1 + 3 print(init1) else: init2 = init2 + 5 print(init2) def sereis2(n): mul = 1 term = 0 for i in range(n): term = term + 3 * mul mul = mul + 2 print(term) while(1): print(" Menu") print("1. Series 1 : 8, 7, 11, 12, 14, 17, 17, 22, ?") print("2. Series 2 : 3, 12, 27, 48, 75, 108, ?") print("3. Exit") ch = int(input("Enter your choice:")) if(ch==1): n = int(input("Enter the number of terms (greater than 2) :")) series1(n) elif(ch==2): n = int(input("Enter the number of terms :")) series2(n) elif(ch==3): break else: print("Wrong Choice") DO IT YOUR SELF...

CODING : #CONCATENATION OF TWO DICTIONARIES D1={'A':1,'B':2, 'C':3} D2={'D':4} D1.update(D2) print(D1)

#COPYING A LIST AND TUPLES IN REVERSE ORDER L1=['Ant',10,56.9,'37.09'] T1=('Turn','51.29','Diary','Copy') L2=[] T2=() L2=L1[::-1] T2=T1[::-1] print("Given List",L1) print("Reverse of the List",L2) print("Given Tuple",T1) print("Reverse of the Tuple",T2)

#CALCULATE TOTAL MARK, PERCENTAGE OF A STUDENT L1=[78,98,88,68,78] L=len(L1) S=sum(L1) print("Total Mark and Percentage of the Student is : ",S,S/L)

PREETI ARORA - PYTHON

GOOGLE CLASSROOM : SECTION A : https://bit.ly/2D6kDIl SECTION B : https://bit.ly/39HeG0l SECTION C : https://bit.ly/33c23JK PERSONAL : https://bit.ly/33cmHJM GOOGLE MEET : https://bit.ly/339Etgw GOOGLE DRIVE :https://bit.ly/3fiBPYe ISHAREYOU : https://bit.ly/2Dipaar YOUTUBE : https://bit.ly/33buZBi BITLY.COM : SHUNSUNDARS@GMAIL.COM

# To find Fibonacci series : 0,1,1,2,3,5,8,13,... as a LIST Object and # its 'N'th term using Recursion def fibo(num): a=0 b=1 fib=[a,b] for i in range(3,num+1): c=a+b fib.append(c) a=b b=c return fib def nthfiboterm(n): if n<=1: return n else: return (nthfiboterm(n-1)+nthfiboterm(n-2)) num = int(input("Enter the 'n'th term to find in fibonacci :")) term =nthfiboterm(num-1) print("Fibonacci Series : ",fibo(num)) print(num,"th term of fibonacci series is :",term)

#Program to find sum of elements of list recursively def findSum(lst,num): if num==0: return 0 else: return lst[num-1]+findSum(lst,num-1) 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(i+1)+":")) mylist.append(n) #Adding number to list sum = findSum(mylist,len(mylist)) print("Sum of List items ",mylist, " is :",sum)

#Program to input any number from user #Check it is Prime number of not import math num = int(input("Enter any number :")) isPrime=True for i 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 ##")

Weekly Test QB-MySQL functions, Sorting and Grouping clauses

# To calculate factorial of a given number def fact(n): if n > 1: return n*fact(n-1) else: return n num = int(input("Enter any number :")) print("Factorial of ", num , " is :",fact(num))

#Updating a Record import mysql.connector as mcr cn = mcr.connect(host='127.0.0.1',user='root',password="admin",database="company") cr = cn.cursor() print("#"*40) print(" EMPLOYEE UPDATION FORM") print("#"*40) ans='y' while ans.lower()=='y': eno = int(input("ENTER EMPNO TO UPDATE :")) query="select * from employee where empno={}".format(eno) cr.execute(query) result = cr.fetchall() if cr.rowcount==0: print("Sorry! Empno not found ") else: print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT","%10s"%"SALARY") for row in result: print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3]) choice=input("\n## ARE YOUR SURE TO UPDATE ? (Y) :") if choice.lower()=='y': print("== YOU CAN UPDATE ONLY DEPT AND SALARY ==") print("== FOR EMPNO AND NAME CONTACT ADMIN ==") d=input("ENTER NEW DEPARTMENT,(LEAVE BLANK IF NOT WANT TO CHANGE )") if d=="": d=row[2] try: s = int(input("ENTER NEW SALARY,(LEAVE BLANK IF NOT WANT TO CHANGE ) ")) except: s=row[3] query="update employee set dept='{}',salary={} where empno={}".format(d,s,eno) cr.execute(query) cn.commit() print("## RECORD UPDATED ## ") ans=input("UPDATE MORE (Y) :")

#Deleting a Record import mysql.connector as mcr cn = mcr.connect(host='127.0.0.1',user='root',password="admin",database="company") cr = cn.cursor() print("#"*40) print(" EMPLOYEE DELETION FORM") print("#"*40) ans='y' while ans.lower()=='y': eno = int(input("ENTER EMPNO TO DELETE :")) query="select * from employee where empno={}".format(eno) cr.execute(query) result = cr.fetchall() if cr.rowcount==0: print("Sorry! Empno not found ") else: print("%10s"%"EMPNO","%20s"%"NAME", "%15s"%"DEPARTMENT","%10s"%"SALARY") for row in result: print("%10s"%row[0],"%20s"%row[1],"%15s"%row[2],"%10s"%row[3]) choice=input("\n## ARE YOUR SURE TO DELETE ? (Y) :") if choice.lower()=='y': query="delete from employee where empno={}".format(eno) cr.execute(query) cn.commit() print("=== RECORD DELETED SUCCESSFULLY! ===") ans=input("DELETE MORE ? (Y) :")