083 - XI - CS - Practical Programs
083 - XI - CS - Practical Programs
AIM : To create python program to input two numbers and display larger and smaller number
RESULT : Thus, the above Python program is executed successfully and the output is verified.
AIM : To create Input three numbers and display the largest/smallest number Python
Program
else:
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 3 : Patterns using nested for Loop in Python
AIM : To write a python program to display the following patterns using nested for Loop
pattern #1
print('*',end='')
print('')
Output
**********
**********
**********
**********
**********
pattern #2
for i in range(10):
for j in range(10-i):
print('*',end='')
print('')
**********
*********
********
*******
******
*****
****
***
**
*
pattern #3
for i in range(1,9):
for j in range(i):
print('*',end='')
print('')
*
**
***
****
*****
******
*******
********
pattern #4
for i in range(1,11):
for k in range(i,10):
print(' ',end='')
for j in range(2*i-1):
print('*',end='')
print('')
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
pattern #5
for i in range(11,0,-1):
for k in range(i,11):
print(' ',end='')
for j in range((2*i)-1):
print('*',end='')
print('')
*********************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
pattern #6
for i in range(0,12):
for k in range(i,11):
for j in range((2*i)): #
print('')
**********************
********** **********
********* *********
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
RESULT : Thus, the above Python program is executed successfully and the output is verified.
i=0 # counter
while( i<n):
temp=n1+n2
n1=n2
n2=temp
i = i+1
RESULT : Thus, the above Python program is executed successfully and the output is verified.
AIM : To calculate factorial of a number given by the user using for loop
#Finding maximum
for i in l:
if i>m:
m=i
print("The lasrgest number is:",m)
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 6 : Write a program to swap elements at the even location with the elements
odd location.
AIM : To Write a program to swap elements at the even location with the elements odd
location.
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 7 : Write a python program to create a tuple and print a square of each element.
AIM : To Write a python program to create a tuple and print a square of each element.
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 8 : Write a program to accept string into tuple and extract the digits into a new
list. Print the extracted numeric list.
AIM : Write a program to accept string into tuple and extract the digits into a new list.
Print the extracted numeric list.
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 9 : Write a program to create a dictionary with the roll number, name and
marks of n students in a class and display the names of students who have marks
above 75.
AIM : Write a program to create a dictionary with the roll number, name and marks of n
students in a class and display the names of students who have marks above 75.
#Empty Dictionary
stu={}
#Data Input
for i in range(n):
print("Enter details of student:")
rn=int(input("Enter roll number:"))
name=input("Enter Name:")
marks=float(input("Enter Marks:"))
stu[rn]=[name,marks]
#Logic to display detail of students more than 75 marks
for i in stu:
if stu[i][1]>75:
print("Name:",stu[i][0],"Marks:",stu[i][1])
RESULT : Thus, the above Python program is executed successfully and the output is verified.
1. Show record
2. Add new customer
3. Delete a customer
4. Search record
5. Update record
6. Sort record
7. Exit
n=int(input("How many customers:"))
cust={}
for i in range(n):
print("Enter details of customer:",i+1)
cname=input("Enter name of customer:")
pn=int(input("Enter Phone number:"))
cust[cname]=pn
c=0
while c!=7:
print('''
1. Show record
2. Add new customer
3. Delete a customer
4. Search record
5. Update record
6. Sort record
7. Exit
''')
c=int(input("Enter your choice:"))
if c==1:
for i in cust:
print(i,":",cust[i])
elif c==2:
print("Enter details of new customer:")
cname=input("Enter name:")
pn=int(input("Enter phone number:"))
cust[cname]=pn
elif c==3:
nm=input("Enter name to be deleted:")
f=cust.pop(nm,-1)
if f!=-1:
print(f, " is deleted successfully.")
else:
print(f, " not found.")
elif c==4:
name=input("Enter Customer Name:")
if name in cust:
print(name, " found in the record.")
else:
print(name, " not found in the record.")
elif c==5:
cname=input("Enter Customer Name:")
pn=int(input("Enter phone number to modify:"))
cust[cname]=pn
elif c==6:
l=sorted(cust)
for i in l:
print(i,":",cust[i])
elif c==7:
break
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 11 : Python program to find the highest 2 values in the dictionary.
AIM : To write a python program to find the highest 2 values in the dictionary.
s=sorted(std.values())
print("Top two values:",s[-1],s[-2])
RESULT : Thus, the above Python program is executed successfully and the output is verified.
Ex 12 : Python Program to choose any 4 customers randomly for lucky winners out
of 100 customers
AIM : To write a Python Program to choose any 4 customers randomly for lucky winners
out of 100 customers
Import random
c1=random.randint(1,100)
c2=random.randint(1,100)
c3=random.randint(1,100)
c4=random.randint(1,100)
print("Lucky winners are:",c1,c2,c3,c4)
RESULT : Thus, the above Python program is executed successfully and the output is verified.
import string
ch=0
while ch!=7:
print('''
1. Display the ascii letters
2. Display the digits
3. Display Hexadedigits
4. Display Octaldigits
5. Display Punctuation
6. Display string in title case
7. Exit
''')
ch=int(input("Enter your choice:"))
if ch==1:
print(string.ascii_letters)
elif ch==2:
print(string.digits)
elif ch==3:
print(string.hexdigits)
elif ch==4:
print(string.octdigits)
elif ch==5:
print(string.punctuation)
elif ch==6:
s=input("Enter sentence:")
print(string.capwords(s))
elif ch==7:
break
RESULT : Thus, the above Python program is executed successfully and the output is verified.