Saturday, September 28, 2019

Unit 4

Write a program to create a database named “Sample_DB” in MySQL(). [First ensure connection is made or not and then check if the database Sample_DB already exists or not, if yes then print appropriate message

import mysql.connector as mydb

try:
    pydb=mydb.connect(host="localhost",user="root",passwd="")
except:
    print("error in create database")
 
try:
    pycursor=pydb.cursor()
    pycursor.execute("create database d4")
    pycursor.close()
    print("created")
except:
    print("wrong")


Write a program to retrieve and display all the rows in the employee table. [First create an employee table in the Sample_DB with the fields as eid, name, sal . Also enter some valid records]

import mysql.connector as mydb

try:
    pydb=mydb.connect(host="localhost",user="root",passwd="",database="d4")
except:
    print("connection")

try:
    pycursor=pydb.cursor()
    pycursor.execute("select * from t3")
    res = pycursor.fetchall()
    for i in res:
        print(i)
    pycursor.close()
except:
    print("wrong")


Write a program to insert several rows into employee table from the keyboard.

import mysql.connector as mydb

try:
    pydb=mydb.connect(host="localhost",user="root",passwd="",database="d4")
except:
    print("connection")

#try:
''' pycursor=pydb.cursor()
    pycursor.execute("CREATE TABLE t3 (id int(5) , name varchar(255) , address varchar(255))")
    pycursor.close()

    pycursor=pydb.cursor()
    pycursor.execute("Show tables")
    for i in pycursor:
        print(i)
    pycursor.close()
  '''
try:
    pycursor=pydb.cursor()
    pycursor.execute("insert into t3 values (1,'a','vatva')")
    pydb.commit()
    pycursor.close()
    print("inserted")
except:
    print("wrong")


Write a program to delete a row from an employee table by accepting the employee identity number (eid) from the user.

import mysql.connector as mydb

try:
    pydb=mydb.connect(host="localhost",user="root",passwd="",database="d4")
except:
    print("connection")

try:
    pycursor=pydb.cursor()
    pycursor.execute("delete from t3 where id=2")
    pydb.commit()
    pycursor.close()
except:
    print("wrong")


Write a program to increase the salary (sal) of an employee in the employee table by accepting the employee identity number (eid) from the user.

import mysql.connector as mydb

try:
    pydb=mydb.connect(host="localhost",user="root",passwd="",database="d4")
except:
    print("connection")

try:
    pycursor=pydb.cursor()
    pycursor.execute("update t3 set name='vicky' where name='a'")
    pydb.commit()
    pycursor.close()
except:
    print("wrong")


Write a program to create a table named new_employee_tbl with the fields eno , ename , gender and salary in Sample_DB database. The datatypes of the fields are eno-int, ename-char(30), gender-char(1) and salary-float.

import mysql.connector as mydb

#(eno int(5) , ename varchar(10), gender varchar(5), sal int(7))



def create_tb():
    try:
        pycursor=pydb.cursor()
        pycursor.execute("create table t6 (eno int(5) , ename varchar(10), gender varchar(5), sal int(7))")
        pycursor.close()
    except:
        print("wrong in table create")
    else:
        print("created")

#start
        
try:
    pydb=mydb.connect(host="localhost",user="root",passwd="",database="d4")
except:
    print("connection wrong")
else:
    try:
        create_tb()
    except:
        print("wrong")


Unit 3

'''
Write a program to create a Student class with name, age and marks as data members.
Also create a method named display() to view the student details. Create an object to
Student class and call the method using the object
'''

class Stud:
    def __init__(self,name,age,mark): # this is Constructor double(__) define special function
        self.name = name
        self.age = age
        self.mark = mark
    def disp(self):
        print(self.name)
        print(self.age)
        print(self.mark)


s = Stud('vikas',19,49)
s.disp()


'''
Write a program to create a static method that counts the number of instances
created for a class. 
'''

class stud:
    a=0
    def __init__(self):
        stud.a += 1
    @staticmethod
    def disp():
        print(stud.a)

s = stud()
s1 = stud()
s1.disp()

Create a Student class to with the methods set_id, get_id, set_name, get_name, set_marks and get_marks where the method name starting with set are used to assign the values and method name starting with get are returning the values. Save the program by student.py. Create another program to use the Student class which is already available in student.py.


class stud:
    def setid(self,id):
        self.id = id
    def getid(self):
        return self.id
    def setname(self,name):
        self.name = name
    def getname(self):
        return self.name
---------------------------

from stud9 import stud

s = stud()
s.setid(1)
s.setname('vikas')

print(s.getid())
print(s.getname())

Write a program to access the base class constructor from a sub class by using super() method and also without using super() method.

class father:
    def __init__(self,no):
        self.no = no
    def disp(self):
        print(self.no)

class son(father):
    def __init__(self,no,name):
        super().__init__(no)
        self.name= name
    def disp(self):
        super().disp()
        print(self.name)

s = son(8,'vikas')
s.disp()


Write a program to implement single inheritance in which two sub classes are derived from a single base class.

class Bank():
    cash=10000
    @classmethod
    def total(cls):
        print("Bank total -> ",cls.cash)

class State(Bank):
    cash = 20000
    @classmethod
    def total(cls):
        print("State total -> ",cls.cash)
    
class Adc(Bank):
    cash = 30000
    @classmethod
    def total(cls):
        print("Total -> ",Bank.cash + cls.cash)

s = State()
s.total()
a = Adc()
a.total()

Write a program to override the super class method in subclass.

class Squares():
    def fun(self,a,b):
        self.a = a
        self.b = b
    def disp(self):
        print("Square -> ",self.a * self.a)

class Rect(Squares):
    def fun(self,a,b):
        self.a = a
        self.b = b
        #super().fun(a,b)
        
    def disp(self):
        print("Rectangle -> ",self.a * self.b)
        #super().disp()



r = Rect()
r.fun(5,3)
r.disp()



Unit 2

'''
 3. Write a program to understand various methods of array class mentioned:
     append, insert, remove, pop, index, tolist and count'''

import array as arr
a=arr.array('i',[])
n=int(input("Enter How Many Element You Eant  : "))
for i in range(n):
a.append(int(input("Enter Element : ")))

print("Element in array are : ",a)
i,n=[int(j) for j in input("Enter Position of insert Element : ").split()]
a.insert(i,n)

print("After Insertion Element Are : ",a)

rem=int(input("Remove : "))
a.remove(rem)

print(f"After Removal of {rem} element are {a}")
print("Element Deleted Pop is : ",a.pop())
print("After deletion Element are : ",a)

temp=int(input("Enter Element Search in array : " ))
print(f"Element is {temp} is a Position of{a.index(temp)} in array")

lst=a.tolist()
print("Convrted array into list is : ",lst)

cnt=int(input("Enter Element to find total occurence in array : "))
print(f"{cnt} occured : {a.count(ant)} times")


'''
4. Write a program to sort the array elements using bubble sort technique.  '''

import array as arr
a=arr.array('i',[])
n=int(input("enter How Many Element You want : "))
for i in range(n):
    a.append(int(input("Enter Element : ")))
print("Before Swaping : ",a)
for i in range(n):
    for j in range(0,n-i-1):
        if a[j]>a[j+1]:
            a[j],a[j+1]=a[j+1],a[j]
print("sorted list = ",a)


'''
Write a python program that removes any repeated items from a list so that each
item appears at most once. For instance, the list [1,1,2,3,4,3,0,0]
 would become [1,2,3,4,0]
'''

l = [1,1,2,3,4,3,0,0]

print("old list :",l)
s= set(l)
l1 = list(s)
print("new list :",l1)


#Write a program to show variable length argument and its use

def fun(a,*b):
    s=0
    for i in b:
        s += int(i)
    print("total :",s+a)

fun(1,2)
print("-----------")
fun(1,2,3,4,5)


#Write a lambda/Anonymous function to find bigger number in two given numbers

x=lambda a,b: a if a>b else b

a = int(input("enter a: "))
b = int(input("enter b: "))

print("biggest no is :",x(a,b))


'''
Create a program name “employee.py” and implement the functions
DA, HRA, PF ITAX. Create another program that uses the function of
employee module and calculates gross and net salaries of an employee
'''
import ex as f

f.da(500)
f.hra(550)
f.pf(600)
f.itax(900)


'''
Write a program to create a list using range functions and perform
append, update and delete elements operations in it. '''

l = []

n = int(input("how manny no:"))
for i in range(n):
    l.append(int(input("enter NO:")))

print(l)

l[1] = 22
print("afte Update ",l)
del l[2]
print("afte del ",l)


'''
Create a sample list of 7 elements and implement the List methods mentioned:
append, insert, copy, extend, count, remove, pop, sort, reverse and clear.   '''

l=[]

n= int(input("how manny ho :"))

for i in range(n):
    l.append(int(input("enter no:")))

print(l)

p= int(input("enter possion: "))
no= int(input("enter no : "))
print("afte inserted:",l)

l.insert(p,no)
print(l)

p= int(input("enter search no: "))
ind = l.index(p)
print("posion is  :",ind)


'''
 Write a program to accept elements in the form of a tuple and display
 its minimum, maximum, sum and average
 '''

t = (1,2,3,48,0)

print(t)

print(min(t))
print(max(t))
print(sum(t))
avg = sum(t)/len(t)
print(avg)


d1={}

n = int(input("how manny"))

for i in range(n):
    a=input("enter name")
    b=input("scor")
    d1.update({a:b})

print("player list")
for i in d1.keys():
    print(i)

#get() thi value return karse.. // -1 defualt che...
    
name=input("ebter playter name for his score")
run=d1.get(name,-1)

if run == -1:
    print("not found")
else:
    print(f"{name} - {run}")

Unit 1

# 1. Write a program to swap two numbers without taking a temporary variable.


a,b=[int(i) for i in input("Enter Two Number : ").split()]
print(a,b)

a,b = b,a

print(a,b)

# 5. Write a program to find out and display the common and the non common
#    elements in the list using membership operators

a=[]
b=[]
n=int(input("enter how many element"))

for i in range(0,n):
    a.append(input("enter element A"))
    b.append(input("enter element B"))

seta=set(a)
setb=set(b)
if seta & setb:
    print("common Element are :",seta & setb)

if seta ^ setb:
    print("non common Element are :",seta ^ setb)

''' 6. Create a program to display memory locations of two variables using id()
      function, and then use identity operators two compare whether two objects
      are same or not.'''

a,b=[int(i) for i in input("Enter Two Number : ").split()]

print("Memory location of a is : ",id(a))
print("Memory location of b is : ",id(b))

if a is b:
    print("Same")
else:
    print("Not Same")


''' 8. Write a python program to find the sum of even numbers using command line
    arguments.'''


import sys

a = sys.argv

print("argument is -> " , a)

print("---------")
t = 0
for i in a[1:]:
    t = t + int(i)
print(t)


'''
9. Write a menu driven python program which perform the following:
    Find area of circle
    Find area of triangle
    Find area of square and rectangle
    Find Simple Interest Exit. '''

import math
while 1:
    print("1. area of circle")
    print("2. area of triangle")
    print("3. are of squere and rectangle")
    print("4. Simple Interest ")
    print("5. Exit")
    ch = int(input("Enter choise "))

    if ch == 1:
        p = int(input("Enter Radious:"))
        print(p * p * math.pi)

    elif ch == 2:
        n1 = int(input("Enter N1 :"))
        n2 = int(input("Enter N2 :"))
        n3 = int(input("Enter N3 :"))
        t = n1 + n2 + n3 / 2
        s = t*(n1 - t)*(n2 - t)*(n3 - t) ** 0.5
        print(s)

    elif ch == 3:
        s = int(input("Enter no of Squere:"))
        l = int(input("Enter lengh:"))
        w = int(input("Enter width:"))
        print("Squere is = ",s*s)
        print("Rectangle is = ",l*w)

    elif ch == 4:
        p = int(input("Enter Price :"))
        r = int(input("Enter Rate :"))
        n = int(input("Enter year :"))
        print(p * r * n / 100)
    
    elif ch == 5:
        exit(0)


'''
11.  Write a program to search an element in the list using for loop and
        also demonstrate the use of “else” with for loop. '''
l = [1,5,10,15,20,25] 

print("List is = ", l)


s = int(input("Enter Search Element:"))

for i in l:
    if s == i:
        print("find element")
        break;
if s != int(i):
    print("not find")


''' 12.  Write a python program that asks the user to enter a length in centimeters.
         If the user enters a negative length, the program should tell the user
         that the entry is invalid. Otherwise, the program should convert the
         length to inches and print out the result. (2.54 = 1 inch)'''

print("Convert inch into Centimeter")

inch = float(input("Enter inch "))

if inch > 0:
    t = inch * 2.54
    print(t)
else:
    print("Invalid Number ")


cent = float(input("Enter Centementer "))

if cent > 0:
    t = cent / 2.54
    print("ans is %.2f"%t)
else:
    print("Invalid Number ")

Sunday, December 30, 2018

Notepad/Textpad (Implement Textpad application using Richtextbox.)





https://youtu.be/jNxtpdN9-VY

Tuesday, December 25, 2018

Enter a Sentence Number of vowels, spaces, digits, special symbols When ...





https://youtu.be/CVU1WRiFC-s

Monday, December 24, 2018

Design a form having Combo box has options like 'ADD', 'SUB', 'MUL' and ...





https://youtu.be/tSWt9Q9Kns4


Convert the Celsius to Fahrenheit and convert Fahrenheit to Celsius in C...





https://youtu.be/JZah3G6sImw

Design interface and implement functionalities for Loan calculator in C#...





https://youtu.be/wjkM6H-OqRE

Sunday, December 23, 2018

Arithmetic Calculator for C# (Microsoft Visual Studio)







https://youtu.be/HLzMcIdDHDA

Wednesday, March 28, 2018

Count number of lines, words and characters in a file.

https://youtu.be/JtIhlMxqXb0