You are on page 1of 14

Computer

Science (083)

Assignment

Work

Made by:
Tanu shree
Class: XII-A
Roll No. ______
Python Programming
1. Write a program in python to check a number whether it is prime or not

num=int(input("Enter the number: "))


for i in range(2,num):
if num%i==0:
print(num, "is not prime number")
break
else:
print(num,"is prime number")

2. Write a program to check a number whether it is palindrome or not.

num=int(input("Enter a number : "))


n=num
res=0
while num>0:
rem=num%10
res=rem+res*10
num=num//10
if res==n:
print("Number is Palindrome")
else:
print("Number is not Palindrome")

3. Write a program to calculate compound interest.


p=float(input("Enter the principal amount : "))
r=float(input("Enter the rate of interest : "))
t=float(input("Enter the time in years : "))

x=(1+r/100)**t

CI= p*x-p
print("Compound interest is : ", round(CI,2))

4. Write a program to display ASCII code of a character and vice versa.

var=True
while var:
choice=int(input("Press-1 to find the ordinal value of a character \nPress-2 to find a character of a
value\n"))
if choice==1:
ch=input("Enter a character : ")
print(ord(ch))
elif choice==2:
val=int(input("Enter an integer value: "))
print(chr(val))
else:
print("You entered wrong choice")

print("Do you want to continue? Y/N")


option=input()
if option=='y' or option=='Y':
var=True
else:
var=False

5. Write a program to input a character and to print whether a given character is an


alphabet, digit or any other character.
ch=input("Enter a character: ")
if ch.isalpha():
print(ch, "is an alphabet")
elif ch.isdigit():
print(ch, "is a digit")
elif ch.isalnum():
print(ch, "is alphabet and numeric")
else:
print(ch, "is a special symbol")

6. Write a program to calculate the factorial of an integer using recursion.

def factorial(n):
if n == 1:
return n
else:
return n*factorial(n-1)

num=int(input("enter the number: "))


if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of ",num," is ", factorial(num))

7. Write a program to print fibonacci series using recursion.


def fibonacci(n):
if n<=1:
return n
else:
return(fibonacci(n-1)+fibonacci(n-2))

num=int(input("How many terms you want to display: "))


for i in range(num):
print(fibonacci(i)," ", end=" ")

8. Write a program for binary search.

def Binary_Search(sequence, item, LB, UB):


if LB>UB:
return -5
# return any negative value
mid=int((LB+UB)/2)
if item==sequence[mid]:
return mid
elif item<sequence[mid]:
UB=mid-1
return Binary_Search(sequence, item, LB, UB)
else:
LB=mid+1
return Binary_Search(sequence, item, LB, UB)

L=eval(input("Enter the elements in sorted order: "))


n=len(L)
element=int(input("Enter the element that you want to search :"))
found=Binary_Search(L,element,0,n-1)
if found>=0:
print(element, "Found at the index : ",found)
else:
print("Element not present in the list")

9. Write a recursive python program to test if a string is palindrome or not.


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

#__main__

s=input("Enter the string : ")


y=isStringPalindrome(s)

if y==True:
print("String is Palindrome")
else:
print("String is Not Palindrome")

10. Write a program to calculate EMI for a loan using numpy.

import numpy as np

interest_rate= float(input("Enter the interest rate : "))


monthly_rate = (interest_rate)/ (12*100)

years= float(input("Enter the total years : "))


number_month = years * 12

loan_amount= float(input("Enter the loan amount : "))

emi = abs(np.pmt(monthly_rate, number_month, loan_amount))

print("Your EMI will be Rs. ", round(emi, 2))


11. Write a program toget employee details from a given file.

import csv
with open('emp.csv') as csvfile:
myreader = csv.reader(csvfile,delimiter=',')
count=0
print("%10s"%"EMPNO","%20s"%"EMP NAME","%10s"%"SALARY")
print("==================================================")
for row in myreader:
print("%10s"%row[0],"%20s"%row[1],"%10s"%row[2])
count+=1
print("==================================================")
print("%30s"%"TOTAL RECORDS :", count)
print("==================================================")

12. Write a program to create a library in python and import it in a program.

L=eval(input("Enter the elements: "))


n=len(L)
item=eval(input("Enter the element that you want to search : "))
for i in range(n):
if L[i]==item:
print("Element found at the position :", i+1)
break
else:
print("Element not Found")

13. Write a program for bubble sort.


L=eval(input("Enter the elements:"))
n=len(L)
for p in range(0,n-1):
for i in range(0,n-1):
if L[i]>L[i+1]:
t=L[i]
L[i]=L[i+1]
L[i+1]=t
print("The sorted list is : ", L)

MYSQL Practical
14. Creating and inserting the tables
Create table (table name)
(<column name><data type>[(size)]

15. Selecting all data


16. ORDER BY CLAUSE

17. SUM AND DISTINCT

18. COUNT
19. SELECTING THE PARTICULAR COLUMN

20. Create a table name Emp with following structure (EmpID primary key)

EmpID EmpName Designation DOJ Sal Comm


Number Varchar Char(10) Date Number Number

Write a query to display all the records with all the columns.

21. Write a query to display EmpName and Sal of employees whose salary are greater
than or equal to 2200.
22.Display the distinct designation in the organization.

23.Display the name of Employees who are working as Manager or Analyst.

24. Consider the following tables SCHOOL and ADMIN. Write sql commands for the
statement 1 to 5.

25. To display TeacherName, Periods of all teachers whose working experience is more
than 10 years.
26. To display teachername, periods of all teachers whose periods less than 25.

27. To display teachername, gender and subject of all teachers who have joined the
school after 01/01/1999.

28. Display the sum of salaries of each department.

MySql-Python-Connector
29. Create a Python program that connects MySQL database by creating a table
Teacher_Detail in database School.

import mysql.connector as m
mdb = m.connect(host="localhost",user="root",passwd ="tiger",database ="school")
print(mdb)
cr = mdb.cursor();
cr.execute("Create table Teacher_Detail(Id char(4) Primary key, Name varchar(15), price decimal(5,2))")
print("table created succesfully")
cr.execute("Show tables")
for x in cr:
print(x)
30. Create a Python program that connects MySQL database by inserting 5 values in a
table Student in database School.

import mysql.connector as m
mdb=m.connect(host="localhost",user="root", passwd="tiger", database="school")
print(mdb)
cr=mdb.cursor();
cr.execute("Insert into student values(11,'Janvi',390.5)")
cr.execute("Insert into student values(12,'Himani',450.0)")
cr.execute("Insert into student values(13,'Naincy',400.00)")
cr.execute("Insert into student values(14,'Harish',460.5)")
cr.execute("Insert into student values(15,'Abhay',375.5)")
mdb.commit()
jumnhygtfz print("Record Inserted succesfully")
cr.execute("Select * from student")
rec=cr.fetchall()
for x in rec:
print(x)
print(cr.rowcount,"Record Inserted")
mdb.close()

*****THANK YOU*****

You might also like