Blank
Blank
ROLL NO.: 12
CLASS: XI-Com. B
CERTIFICATE
The programs entered in this file has been satisfactorily performed by
__________________
__________________
Subject Teacher’s Sign. Examiner’s
Sign.
____________________
___________________
Principal’s Sign. School
Stamp
Index
1. Take two integer values from user and print greatest among them.
2. A shop will give discount of 10% if the cost of purchased quantity is more
than 1000.Ask user for quantity
suppose, one unit will cost 100. Print total cost for user.
3. A student will not be allowed to sit in exam if his/her attendance is less than
75%.
Take following input from user Number of classes held, Number of classes
attended.And print percentage of class attended.
4. Write a program that reads three numbers and prints them in ascending
order.
5. Write a program to check the given year is leap year or not. If a year is
divisible by 4 then it is leap year but if the year is century year like 2000,
1900, 2100 then it must be divisible by 400.
6. Write a program to find factorial of a given number.
7. Write a program to find sum of the series : S = 1 + X + X2 + X3 + X4 +……
+Xn
8. Write a python script to print first 15 elements of Fibonacci series.
Fibonacci series – 0 1 1 2 3 5 8 13………
12.Write a program to find the largest and the second largest elements in a
given list of elements.
13.Write a program to read a list of n integers and find their median.
Note: The median value of a list of values is the middle one when they are
arranged in order. If there are two middle values then take their average.
Hint: Use an inbuilt function to sort the list.
14.Write a program to read a list of elements. Modify this list so that it does not
contain any duplicate elements i.e. all elements occurring multiple times in
the list should appear only once.
15.Write a program to create a list of elements. Input an element from the user
that has to be inserted in the list. Also input the position at which it is to be
inserted.
16.Write a program to create a dictionary to store names of states and their
capitals.
17.Write a program to create a dictionary to store assets, liabilities and capital
of a company. After creating the dictionary display, assets and liabilities of
the company and test of the accounting equation holds true.
18.Write a program to check if a dictionary is empty.
19.Write a program to create a third dictionary from two dictionaries having
some common keys, in way so that the values of common keys are added in
the third dictionary.
20.Write a program to input your friend’s names and their phone numbers and
store them in the dictionary as the key-value pair. Perform the following
operations on the dictionary:
a. Display the name and phone number of all your friends.
b. Add a new key-value pair in this dictionary and display the modified
dictionary.
c. Delete a particular friend from the dictionary.
d. Modify the phone number of an existing friend.
e. Check if a friend is present in the dictionary or not.
f. Display the dictionary in sorted order of names.
Program-1:
Take two integer values from user and print greatest
among them.
Code:
#Python program to find Largest of two Numbers using if-else
statements
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
if(a>=b):
print(a,"is greater")
else:
print(b,"is greater")
Output:
Program-2:
A shop will give discount of 10% if the cost of purchased
quantity is more than 1000. Ask user for quantity. Suppose
one unit will cost 100.Print total cost for user.
Code:
x=int(input("Enter quantity:"))
if x*100>1000:
print("the cost of user is",x*100-(x*100*0.1))
else:
print("the total cost of user is",x*100)
Output:
Program-3:
A student will not be allowed to sit in exam if his/her
attendance is less than 75%. Take input from user
Number of classes held, Number of classes attended.
Print percentage of class attended.
Code:
x=int(input("enter the number of classes held:"))
y=int(input("enter the number of classes attended:"))
if(x/y)*100>+75:
print("the student had attended”,(x/y)*100,"classes and is
eligible to sit in exam ")
else:
print("the student is not able to sit in exam with",(x/y)*100)
Output:
Program-4:
Program that reads three numbers and prints them in ascending
order.
Code:
num1=int(input("Enter the first number:"))
num2=int(input("Enter the second number:"))
num3=int(input("Enter the third number:"))
if num1<num2 and num1<num3:
if num2<num3:
x,y,z=num1,num2,num3
else:
x,y,z=num1,num3,num2
elif num2<num1 and num2<num3:
if num1<num3:
x,y,z=num2,num1,num3
else:
x,y,z=num2,num3,num1
else:
if num1<num2:
x,y,z=num3,num1,num2
else:
x,y,z=num3,num2,num1
print("The numbers in ascending orders are:",x,y,z)
Output:
Program-5:
Program to check the given year is leap year or not. If a year is
divisible by 4 then it is leap year but if the year is century year
like 2000,1900,2100 then it must be divisible by 400.
Code:
x=int(input("Enter the year:"))
if x%400==0:
print("It is the century leap year")
elif x%4==0 and x%100!=0:
print("It is the leap year")
else:
print("It is not the leap year")
Output:
Program-6:
Write a program to find factorial of a given number.
Code:
f=1
n=int(input("Enter the number:"))
for i in range(n,0,-1):
f=f*i
print(f)
Output:
Program-7:
Write a program to find sum of the series: S = 1 + X + X2 + X3 +
X4 +……+Xn
Code:
x=float(input("enter value:"))
n=int(input("enter value:"))
s=0
for a in range(n+1):
s+=x**a
print("Sum of series is",s)
Output:
Program-8:
Write a program script to print first 15 elements of Fibanacci
series.
Fibonacci series – 0 1 1 2 3 5 8 13………
Code:
f1=0
f2=1
n=int(input("Enter number of series:"))
print()
print(f1,"\t",f2,end='\t')
for i in range(2,n+1):
f3=f1+f2
f1=f2
f2=f3
print(f3,end='\t')
Output:
Program-9:
Write a program to print the following pattern:
(a) A
AB
ABC
ABCD
ABCDE
Code:
n=int(input("enter no. of rows:"))
for i in range(1,n+1):
a=45
for j in range(1,i+1):
print(chr(a),end="")
a+=1
print()
Output:
(b) 5 5 5 5 5
4444
333
22
1
Code:
n=int(input("Enter number:"))
for i in range(n,0,-1):
for j in range(i,0,-1):
print(i,end="")
print()
Output:
(c) 5 4 3 2 1
4321
321
21
1
Code:
for i in range(5,0,-1):
for j in range(i,0,-1):
print(j,end="")
print()
Output:
Program-10:
Input a number and check if the number is a prime number.
Code:
n=int(input("Enter numbers:"))
flag=0
if n>1:
for i in range(2,(n//2)+1):
if n%i==0:
flag=1
break
if flag==0:
print(n,"number is prime.")
else:
print(n,"is not prime.")
else:
print("Enter number greater than 1.")
Output:
Program-11:
Write a program to read a list of n integers (positive as well as
negative). Create two new lists, one having all positive numbers
and the other having all negative numbers from the given list.
Print all three lists.
Code:
l=[]
l1=[]
l2=[]
n=int(input("Enter how many no.u want in your list:"))
for i in range(n):
m=int(input("Enter your number.:"))
l.append(m)
if m>=1:
l1.append(m)
else:
l2.append(m)
print("Here is your original list:\n",l)
print("Here is your positive list:\n",l1)
print("Here is your negative list:\n",l2)
Output:
Program-12:
Write a program to find the largest and the second largest
elements in a given list of elements.
Code:
l=[]
n=int(input("Enter how many number you want:"))
for i in range(n):
m=int(input("Enter your number:"))
l.append(m)
x=sorted(l)
print("Your largest digit in the given list is:",x[-1])
print("Your second largest digit is:",x[-2])
Output:
Program-13:
Write a program to read a list of n integers and find their
median.
Code:
l=[]
n=int(input("Enter how many number do you want in your
list:"))
for i in range(n):
m=int(input("Enter your number here:"))
l.append(m)
l.sort()
print(l)
if n%2==0:
n1=(n//2)
n2=(n//2)+1
m=(l[n1-1]+l[n2-1])/2
print("median of your list is:",m)
else:
n1=(n//2)
m=(l[n1])
print("median of your list is:",m)
Output:
Program-14:
Write a program to read a list of elements. Modify this list so
that it does not contain any duplicate elements i.e. all elements
occurring multiple times in the list should appear only once.
Code:
l=[]
n=int(input("Enter how many number you want in your list:"))
for i in range(n):
m=int(input("Enter your number"))
l.append(m)
ll=[]
for i in l:
if i not in ll:
ll.append(i)
print(l)
print(ll)
Output:
Program-15:
Write a program to create a list of elements. Input an element
from the user that has to be inserted in the list. Also input the
position at which it is to be inserted.
Code:
arr=[12,34,25,56,78,87]
pos=int(input("enter the position where you want to insert the
element:"))
ele=int(input("enter element to insert:"))
print("the list before insertion:",arr)
arr1=arr[:pos-1]+[ele]+arr[pos-1:]
print("the list after insertion:",arr1)
Output:
Program-16:
Write a program to create a dictionary to store names of
States and their Capitals.
Code:
D={}
a=int(input("Enter how many States & Capital do you want:"))
for i in range(a):
S=input("Enter the name of state:")
C=input("Enter the name of capital")
D[S]=C
print(D)
Output:
Program-17:
Write a program to create a dictionary to store assets, liabilities
and capital of a company. After creating the dictionary display,
assets and liabilities of the company and test of the accounting
equation holds true.
Code:
n=int(input("Enter the number of entries:"))
acc_dict=dict()
print()
for i in range(n):
com=input("Enter the name of the company:")
a=float(input("Enter the asset amount:"))
l=float(input("Enter the liability amount:"))
c=float(input("Enter the capital amount:"))
acc_dict[com]=a,l,c
print()
print()
print("Your given dictionary:")
print()
print("Company\t\t","Asset\t\t","Liability\t\t","Capital\t")
print()
for i in acc_dict:
print(i,"/t/t",acc_dict[i][0],"\t",acc_dict[i][1],"\t\t",acc_dict[i]
[2])
print()
for i in acc_dict:
if acc_dict[i][1]+acc_dict[i][2]==acc_dict[i][0]:
print("The accounting equation for",i,"holds True.")
else:
print("The accounting equation for",i,"does not hold True.")
Output:
Program-18:
Write a program to check if a dictionary is empty.
Code:
d={}
n=int(input("Enter how many student you want:"))
for i in range(n):
m=input("Enter your student name:")
b=int(input("Enter your student marks:"))
d[m]=b
print(d)
if(len(d)==0):
print("The dictionary is empty.")
else:
print("The dictionary is not empty.")
Output:
Program-19:
Write a program to create a third dictionary from two
dictionaries having some common keys, in way so that the
values of common keys are added in the third dictionary.
Code:
dict1={}
dict2={}
dict3={}
n=int(input("Enter the number of entries for your first
dictionary:"))
m=int(input("Enter the number of entries for your second
dictionary:"))
print("Enter your first dictionary:")
for i in range(n):
xy=input("Enter your character:")
val=int(input("Enter your value:"))
dict1[xy]=val
print("Enter your second dictionary:")
for i in range(m):
xy=input("Enter your character:")
val=int(input("Enter your value:"))
dict2[xy]=val
print(dict1)
print(dict2)
for i in dict1:
if i in dict2:
dict3[i]=dict1[i]+dict2[i]
print("Your combine key is:",dict3)
Output:
Program-20:
Write a program to input your friend’s names and their phone
numbers and store them in the dictionary as the key-value pair.
Perform the following operations on the dictionary:
a. Display the name and phone number of all your friends.
b. Add a new key-value pair in this dictionary and display the
modified dictionary.
c. Delete a particular friend from the dictionary.
d. Modify the phone number of an existing friend.
e. Check if a friend is present in the dictionary or not.
f. Display the dictionary in sorted order of names.
Code:
#Display the Name and phone number of all your friends.
d={}
d2={}
n=int(input("Enter how many names you want to enter:"))
for i in range(n):
name=input("Enter name of friend:")
number=int(input("Enter phone number:"))
d[name]=number
print("Your dictionary is:\n",d)
MYSQL
(4) Display all details of students who are studying in class XII.
(5) Display name, city and marks from student table who lived in
Mumbai.
(9) Display student’s details for only male students who are in class XI.
(10) Display student’s details for class XII and marks grater than 350.