Friday 31 January 2020

11th C class menu driven program for reference

def prog5_fac():
    print("1st program")
   
def prog15_fib():
    print("2nd program")
   
def prog3_sum():
    print("3rd program")

#main program
ch='y'
while ch == 'y' :
    print("1 for 1st prog, 2 for 2nd prog,3 for 3rd prog and 4 for exit ")
   

    c=int(input("Enter the choice: "))
    if c==1:
        prog5_fac()
    elif c==2:
        prog15_fib()
    elif c==3:
        prog3_sum()
    elif c==4:
        print("Thankyou for using python ")
        break
    print("you want to continue y/n")
    ch=str(input("enter choice y/n"))


output
1 for 1st prog, 2 for 2nd prog,3 for 3rd prog and 4 for exit
Enter the choice: 1
1st program
you want to continue y/n
enter choice y/ny
1 for 1st prog, 2 for 2nd prog,3 for 3rd prog and 4 for exit
Enter the choice: 3
3rd program
you want to continue y/n
enter choice y/ny
1 for 1st prog, 2 for 2nd prog,3 for 3rd prog and 4 for exit
Enter the choice: 2
2nd program
you want to continue y/n
enter choice y/n 4
>>> 

Wednesday 29 January 2020

student table connectivity


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root",database="school")
mycursor=mydb.cursor();
mycursor.execute("CREATE TABLE student1920(Roll int(2) Primary key, Name char(20), class int(2), DOB Date, Gender Char(1), City Char(10), Marks int(3))")


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root".passwd="root",database="studentl")
mycursor=mydb.cursor();
sql="insert into student1920(Roll,Name,class,DOB,Gender,City,Marks) values (%s,%s,%s,%s,%s,%s,%s) "
val=(01,"Nanda",10,1995/06/06,"M","Agra",551)
mycursor.execute(sql,val)
mydb.commit()
print(mycursor.rowcount,"1 Record inserted")


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root".passwd="root",database="student")
mycursor=mydb.cursor();
mycursor.execute(" select sum(marks) from student1920 where city="Mumbai"")
myresult=mycursor.fetchall()
for x in myresult:
     print(x)

Tuesday 28 January 2020

stack menu driven program

s=[]
def isEmpty():
       return s == []
def pus(i):
    s.append(i)
    print(s)
    return s
def po():
    return q.pop()
def size():
    return len(s)
def pr():
        return s
 
while True:
    print('Press a for push')
    print('Press b for pop')
    print('press c for the size')
    print('Press d for display')
    print('Press e for quit')
   
    op = input('What would you like to do')
    if op == 'a':
        n=int(input("enter a number to push"))
        q=pus(n)
    elif op == 'b':
        if isEmpty():
            print('Stack is empty.')
        else:
            print('Deleted value: ',po())
    elif op=='c':
        print(size())
    elif op=='d':
        print(pr())     
    elif op == 'e':
        break                                                                                                                   

Connectivity customer table

import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="root",database="bank")
mycursor=mydb.cursor();
mycursor.execute("CREATE TABLE customer(Cust_ID int(3) Primary key, Name char(20), country char(10))")

import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root".passwd="root",database="bank")
mycursor=mydb.cursor();
sql="insert into customer(Cust_ID,Name,country) values (%s,%s,%s) "
val=(101,"Bhuvanesh","India")
mycursor.execute(sql,val)
mydb.commit()
print(mycursor.rowcount,"1 Record inserted")

import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root".passwd="root",database="bank")
mycursor=mydb.cursor();
mycursor.execute("select country,count(country) from customer group by country")
myresult=mycursor.fetchall()
for x in myresult:
     print(x)

Queue program menu driven

q=[]
def isEmpty():
       return q == []
def enqueue(i):
    q.append(i)
    print(q)
    return q
def dequeue():
    return q.pop(0)
def size():
    return len(q)
def pr():
        return q
 
while True:
    print('Press a for insert')
    print('Press b for delete')
    print('press c for the size')
    print('Press d for display')
    print('Press e for quit')
   
    op = input('What would you like to do')
    if op == 'a':
        n=int(input("enter a number to push"))
        q=enqueue(n)
    elif op == 'b':
        if isEmpty():
            print('Queue is empty.')
        else:
            print('Deleted value: ',dequeue())
    elif op=='c':
        print(size())
    elif op=='d':
        print(pr())     
    elif op == 'e':
        break                                                                                                                   

Recursive program

def fib(n1,n2,n):
    if n==0:
        return
    res=n1+n2
    print(res)
    fib(n2,res,n-1)
def r_fact(n):
    if n==1:
        return n
    else:
        return n*r_fact(n-1)

def is_palindrome(s):
    if len(s) < 1:
        return True
    else:
        if s[0] == s[-1]:
            return is_palindrome(s[1:-1])
        else:
            return False


print("\n  a- fibonacci \n b- factorial \n c- palindrome")
ch=input("enter choice a,b,c")
if ch=='a':
    a=0
    b=1
    n=int(input("How many numbers to be printed: "))
    print(a)
    print(b)
    fib(a,b,n-2)
elif ch=='b':
    #Main program
    n=int(input("enter n"))
    if n==0:
        print("factorial is 1")
    elif n<0:
        print("factorial does not exist")
    else:
        print("factorial is :",r_fact(n))
elif  ch=='c':
    a=str(input("Enter string:"))
    if(is_palindrome(a)==True):
        print("String is a palindrome!")
    else:
        print("String isn't a palindrome!")


Text file program menu driven

def rewr():
    #read a file line by line and print it
    f = open("cs.txt", 'w')
    line1 = "Welcome to 12th Class Python."
    f.write(line1)
    line2="\nPython is a general purpose and high level programming language"
    f.write(line2)
    line3 = "\nReadable and Maintainable Code"
    f.write(line3)
    line4="\nMultiple Paradigms"
    f.write(line4)
    line5 = "\nRobust Standard Library"
    f.write(line5)
    line6="\nSimplify Complex Software Development"
    f.write(line6)
    f.close()
    f = open("cs.txt", 'r')
    text = f.read()
    print(text)
    f.close()

def rem():
    #remove all the lines that contain the character 'a' in a file and write it to another file
    fin=open("D:\\book.txt","r")
    fout=open("D:\\story.txt","a")
    s=fin.readlines()
    for j in s:
        if 'a' in j:
            fout.write(j)
    fout.close()
    fin.close()

def ch4():
    #display those words, which are less than 4 characters
    file=open("D:\story.txt")
    line=file.read()
    c=0
    word=line.split()
    for w in word:
        if len(w)<4:
            print(w)
        file.close

#main program
n=int(input("enter the choice 1-read/write, 2-print a and 3-less 4"))
if n==1:
      rewr()
elif n==2:
      rem()
else:
      ch4()

CS practical Practicing QP and QP with answer


Practicing CS practical question paper: Click here

Practicing CS question paper with answer: Click here

Monday 20 January 2020

Mysql and data base programs ( 4 Practicals)


Practical 1
Aim
* To connect to MySQL Server
* To create a Database Student
* To create a Table Student
* To add 6 rows
* To fetch and display the records

import mysql.connector
#Connection to MySQL Server
con = mysql.connector.connect(host="localhost", user="root", passwd="")
mycursor = con.cursor()

#Creating Student Database
mycursor.execute("DROP DATABASE IF EXISTS student")
mycursor.execute("CREATE DATABASE student")
mycursor.execute("USE student")

#Creating Studentinfo Table
mycursor.execute("DROP TABLE IF EXISTS studentinfo")
mycursor.execute("CREATE TABLE studentinfo (name VARCHAR(30), age INT(3), gender
CHAR(1))")

sql = """INSERT INTO studentinfo(name, age, gender)
VALUES(%s, %s, %s)"""
rows = [('Amit', 18,'M'),('Sudha',17,'F'),('Suma',19,'F'),\
('Paresh',19,'M'),('Ali',17,'M'),('Gargi',17,'F')]
mycursor.executemany(sql, rows)
con.commit()

#To fetch the records and display
sql = "SELECT * FROM studentinfo"
mycursor.execute(sql)
result = mycursor.fetchall()
for row in result:
name = row[0]
age = row[1]
gender = row[2]
print("Name=%s, Age=%d, Gender=%c" % (name,age,gender))
con.close()

output
Name=Amit, Age=18, Gender=M
Name=Sudha, Age=17, Gender=F
Name=Suma, Age=19, Gender=F
Name=Paresh, Age=19, Gender=M
Name=Ali, Age=17, Gender=M
Name=Gargi, Age=17, Gender=F

Practical 2
Aim
* To Connect to database student
* To create a table result
* To add six rows
* To increase marks in Math by 5 for Sudha
* To fetch and display the records

import mysql.connector
#Connection to MySQL Server and database student
con = mysql.connector.connect(host="localhost", user="root", passwd="",\
                                                    database="student")
mycursor = con.cursor()

#Creating result Table
mycursor.execute("DROP TABLE IF EXISTS result")
mycursor.execute("CREATE TABLE result (name VARCHAR(30),\
phys INT(3), chem INT(3), math INT(3))")

#Inserting Rows in to the table
sql = """INSERT INTO result(name, phys, chem, math)
VALUES(%s, %s, %s, %s)"""
rows = [('Amit', 70,76,80),('Sudha',80,85,90),('Suma',50,70,90),\
               ('Paresh',55,60,70),('Ali',80,70,75),('Gargi',80,60,80)]
mycursor.executemany(sql, rows)
con.commit()

# Increasing marks of math by 5 for Sudha
sql = "UPDATE result SET math=math+5 WHERE name='%s'" % ('Sudha')
mycursor.execute(sql)

#To fetch the records and display
sql = "SELECT * FROM result"
mycursor.execute(sql)
result = mycursor.fetchall()
for row in result:
      name = row[0]
      p = row[1]
      c = row[2]
      m = row[3]
      print("Name=%s, Phys=%d, Chem=%d, Math=%d" % (name,p,c,m))
con.close()

output
Name=Amit, Phys=70, Chem=76, Math=80
Name=Sudha, Phys=80, Chem=85, Math=95
Name=Suma, Phys=50, Chem=70, Math=90
Name=Paresh, Phys=55, Chem=60, Math=70
Name=Ali, Phys=80, Chem=70, Math=75
Name=Gargi, Phys=80, Chem=60, Math=80

Practical 3
Aim
 * To Connect to database student
 * To create a table result
 * To add six rows
 * To delete the rows with math mark
 * To fetch and display the records

import mysql.connector
#Connection to MySQL Server and database student
con = mysql.connector.connect(host="localhost", user="root", passwd="",\
                                                   database='student')
mycursor = con.cursor()

#Inserting Rows in to the table
sql = """INSERT INTO result(name, phys, chem, math)
VALUES(%s, %s, %s, %s)"""
rows = [('Amit', 70,76,80),('Sudha',80,85,90),('Suma',50,70,90),\
                ('Paresh',55,60,70),('Ali',80,70,75),('Gargi',80,60,80)]
mycursor.executemany(sql, rows)
con.commit()

# Deleting the rows with math marks greater or equal to 90
sql = "DELETE FROM result WHERE math>='%d'" % (90)
mycursor.execute(sql)

#To fetch the records and display
sql = "SELECT * FROM result"
mycursor.execute(sql)
result = mycursor.fetchall()
for row in result:
      name = row[0]
      p = row[1]
      c = row[2]
      m = row[3]
      print("Name=%s, Phys=%d, Chem=%d, Math=%d" % (name,p,c,m))
con.close()

Output
Name=Amit, Phys=70, Chem=76, Math=80
Name=Paresh, Phys=55, Chem=60, Math=70
Name=Ali, Phys=80, Chem=70, Math=75
Name=Gargi, Phys=80, Chem=60, Math=80


Practical 4
Aim
 * To connect to database student
 * To create a Table staff
 * To add 6 rows
 * To fetch and display the records of all

import mysql.connector
#Connection to MySQL Server and database student
con = mysql.connector.connect(host="localhost", user="root", passwd="",\
                                                                        database="student")
mycursor = con.cursor()

#Creating result Table
mycursor.execute("DROP TABLE IF EXISTS staff")
mycursor.execute("CREATE TABLE staff (name VARCHAR(30),\
                desg VARCHAR(10), subject VARCHAR(10), salary INT(5))")

# Inserting six rows in staff
 sql = """INSERT INTO staff(name, desg, subject, salary)
VALUES(%s, %s, %s, %s)"""
 rows = [('Amit', 'PGT','CHEM',8000),('Sudha','HDM','BIOL',8500),\ 
               ('Suma','TGT','MATH',9000),('Paresh','PGT','HIND',7000),\
               ('Ali','PRT','COMM',7500),('Gargi','PGT','COMP',9000)]
mycursor.executemany(sql, rows)
con.commit()
#To fetch the records and display
sql = "SELECT * FROM staff WHERE salary>'%d'" % (8000)
mycursor.execute(sql)
result = mycursor.fetchall()
for row in result:
    name = row[0]
    des = row[1]
    sub = row[2]
    sal = row[3]
    print("Name=%s, Desg=%s, Subject=%s, Salary=%d" % (name,des,sub,sal))
con.close()

output
Name=Sudha, Desg=HDM, Subject=BIOL, Salary=8500
Name=Suma, Desg=TGT, Subject=MATH, Salary=9000
Name=Gargi, Desg=PGT, Subject=COMP, Salary=9000








Thursday 16 January 2020

Write a algorithm and python program to implement statistics (import statistics- mean, median and mode)


# a) mean   (it returns the average value of the set/sequence of value passed

import statistics as s
a=eval(input("Enter the size "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements "))
    seq.append(n)
mea=s.mean(seq)
print("The mean /average value is =",mea)

output
Enter the size 12
Enter the elements 5
Enter the elements 6
Enter the elements 7
Enter the elements 5
Enter the elements 6
Enter the elements 5
Enter the elements 5
Enter the elements 9
Enter the elements 11
Enter the elements 12
Enter the elements 23
Enter the elements 5
The mean /average value is = 8.25

#b) median 

#The median() function returns the median (middle value) of numeric data. When a number # of data points are odd, return the middle data point. When the number of data points is
 # even, a median is interpolated by taking the average of the two middle

import statistics as s
a=eval(input("Enter the size: "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements: "))
    seq.append(n)
mead=s.median(seq)
print("Elements =",seq)
print("The median value is =",mead)

output (even size)
Enter the size: 12
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 6
Enter the elements: 5
Enter the elements: 5
Enter the elements: 9
Enter the elements: 11
Enter the elements: 12
Enter the elements: 23
Enter the elements: 5
Elements = [5, 6, 7, 5, 6, 5, 5, 9, 11, 12, 23, 5]
The median value is = 6.0

Enter the size: 11 (size=odd)
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 16
Enter the elements: 55
Enter the elements: 5
Enter the elements: 5
Enter the elements: 16
Enter the elements: 11
Enter the elements: 12
Elements = [5, 6, 7, 5, 16, 55, 5, 5, 16, 11, 12]
The median value is = 7

# c) mode program (it returns the most often repeated value of the set)

import statistics as s
a=eval(input("Enter the size: "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements: "))
    seq.append(n)
mod=s.mode(seq)
print("Elements =",seq)
print("The median value is =",mod)

Output
Enter the size: 12
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 6
Enter the elements: 5
Enter the elements: 5
Enter the elements: 9
Enter the elements: 11
Enter the elements: 12
Enter the elements: 23
Enter the elements: 5
Elements = [5, 6, 7, 5, 6, 5, 5, 9, 11, 12, 23, 5]
The median value is = 5


Wednesday 15 January 2020

Write a algorithm and python program to implement (import random- random, randint and randrange)

# a) random  Programme  ( 0.0<=N<1.0)

import  random
y=random.random() #
print("Random values 0.0<=N<1.0  is ",y)

output
Random values 0.0<=N<1.0  is  0.2099061497032172
Random values 0.0<=N<1.0  is  0.7191584678625492

#b) randint(a,b)   Programme

import  random
a=int(input("Enter the starting number: "))
b=int(input("Enter the ending number: "))
y=random.randint(a,b)      # a<=N<=b
print(" Range a<=N<=b   "," a= ",a," b= ",b," Random integer  is: ",y )

output
Enter the starting number: 5
Enter the ending number: 15
Range a<=N<=b     a=  5  b=  15  Random integer  is:  12

Enter the starting number: 5
Enter the ending number:  15
 Range a<=N<=b     a=  5  b=  15  Random integer  is:  5

Enter the starting number: 45
Enter the ending number:  75
Range a<=N<=b     a=  45  b=  75  Random integer  is:  67

#c) randrange(<start>,<stop>,<step>)

import  random
a=int(input("Enter the starting number: "))
b=int(input("Enter the ending number: "))
c=int(input("Enter the updating number: "))
y=random.randrange(a,b,c)      # a<=N<=b  updating c

print(" Range a<=N<=b   "," a= ",a," b= ",b,"c= ",c, " Random integer  is: ",y )

output
Enter the starting number: 5
Enter the ending number: 56
Enter the updating number: 5

Range a<=N<=b     a=  5  b=  56  Random integer  is:  45

Enter the starting number: 5
Enter the ending number: 45
Enter the updating number: 7
Range a<=N<=b     a=  5  b=  45 c=  7  Random integer  is:  12


Tuesday 14 January 2020

Write a algorithm and python program to implement( import math- sqrt, ceil, floor, pow, fabs, sin, cos, tan )

# a) sqrt programming

import math
x=int(input(" Enter the x value"))
y=math.sqrt(x)
print("The square root of x value is=",y)

output:
 Enter the x value 64
The square root of x value is= 8.0

# b) ceil programming (Least integer function)

import math
x=eval(input(" Enter the x value"))
y=math.ceil(x)
print("The Least integer is=",y)

output
 Enter the x value 1.03
The Least integer is= 2

output
 Enter the x value -1.03
The Least integer is= -1

# c) floor programming ( Greatest integer function)

import math
x=eval(input(" Enter the x value"))
y=math.floor(x)
print("The Greatest integer is=",y)

output
 Enter the x value 1.03
The Greatest integer is= 1

 output
 Enter the x value -1.03
The Greatest integer is= -2

# d) pow programe
import math
a=int(input(" Enter the a value"))
b=int(input(" Enter the b value"))
y=math.pow(a,b)
print("a to the power b is=",y)

output
 Enter the a value 3
 Enter the b value 4
a to the power b is= 81.0


# e) fabs programming (Modulus function)

import math
a=eval(input(" Enter the a value"))
y=math.fabs(a)
print("Modulus of a is=",y)

output
Enter the a value -6.34
Modulus of a is= 6.34

# f) sin(x) programming

import math
x=eval(input(" Enter the degree value"))
r=math.radians(x)                                  # it converts degrees to radians
y=math.sin(r)                                     
print("sin(x) is =",y)

output
Enter the degree value 30
sin(x) is = 0.49999999999999994

Enter the degree value 0
sin(x) is = 0.0

Enter the degree value  90
sin(x) is = 1.0

# f) cos(x) programming

import math
x=eval(input(" Enter the degree value: "))
r=math.radians(x)                           # it converts degrees to radians
y=math.cos(r)                                     
print("cos(x) is = ",y)

output
Enter the degree value 0
cos(x) is = 1.0

Enter the degree value: 60
cos(x) is =  0.5000000000000001

# f) tan(x) programming


Wednesday 8 January 2020

XI CS PT-2 Periodic Test Blue Print(October to December-19) Max Marks=50

Duration: 1 hour 30 minutes                                                              Total Marks: 50


1. Chapter- List: 05 marks
    * concept - 1 marks
    * Python Program output finding - 1 mark
    * Writing algorithm and python Program -3 marks

2. Chapter-Tuples: 05 marks
    * concept - 1 marks
    * Python Program output finding - 1 mark
    * Writing algorithm and python Program -3 marks

3. Chapter- Dictionary: 05 marks
    * concept- 2 marks
    * Python Program output finding - 1 mark
    * Writing python program - 2 marks

4. Chapter- Sorting: 05 marks
    * concept - 2 marks
    * Writing algorithm and python Program -3 marks

5. Chapter- Strings: 05 marks
    * Definition - 1 mark
    *Python Program output finding -2 marks
    * Writing python program - 2 marks

6. Chapter- Python modules: 05 marks
    * 5 modules each 1 mark

7.Chapter: Relational Data Bases: 05 marks
    * 5 terminologies each 1 mark

8. Chapter: SQL command :  08 marks
   * Differentiation -2 marks
   * Writing SQL query- 2 mark
   * Writing SQL query output-  4 mark

9. Aggregate function(SQL): 05 marks
    * Writing SQL queries - 2 questions each 1 mark
    * Writing output for the SQL queries- 3 questions each 1 mark

10. Basics of NoSQL databases:  02 marks
      * concept - 2 marks