Professional Documents
Culture Documents
Cs Assignment File: Strings Lists Tupples Dictionary SQL
Cs Assignment File: Strings Lists Tupples Dictionary SQL
Strings
Lists
Tupples
Dictionary
SQL
List Programs
1. WAP where list of integers taken by user and passed as
parameter to function named EvenOdd to double the odd
values and half the even values of the list and display the
List
Program –
1. print("Hello User")
2. def EvenOdd(L1):
3. L2=L1
4. Final = []
5. for i in L2 :
6. if i%2==0:
7. Final.append(i/2)
8. elif i%2!=0:
9. Final.append(2*i)
10. return Final
11. def inlist():
12. X = int(input("Enter number of values to be added in the list :
"))
13. Y = []
14. for i in range (X):
15. print("Enter Element",i+1,": ",end="")
16. R = eval(input())
17. Y.append(R)
18. return Y
19. List = inlist()
20. print(EvenOdd(List))
Output –
Hello User
Enter number of values to be added in the list : 3
Enter Element 1 : 12
Enter Element 2 : 21
Enter Element 3 : 23
[6.0, 42, 46]
2. WAP where list of integers taken by the user and Passing
list to function to calculate sum and average of all numbers
and return it in the form of tuple
Program –
1. def inlist():
2. X = int(input("Enter number of values to be added in the list :
"))
3. Y = []
4. for i in range (X):
5. print("Enter Element",i+1,": ",end="")
6. R = eval(input())
7. Y.append(R)
8. return Y
9. def Sum_Avg(L1):
10. Sum = 0
11. Y = len(L1)
12. for i in L1:
13. Sum += i
14. Avg = Sum/Y
15. Tuple = (Sum,Avg)
16. return Tuple
17.
18. X = inlist()
19. Y = Sum_Avg(X)
20. print("List - ",X,"Tuple = ",Y)
Output –
Enter number of values to be added in the list : 5
Enter Element 1 : 13
Enter Element 2 : 12
Enter Element 3 : 13
Enter Element 4 : 12
Enter Element 5 : 50
List - [13, 12, 13, 12, 50] Tuple = (100, 20.0)
3. WAP where list of integers taken by user and Passing two
parameters list to function and number to be searched in
the list and return the position of element in the list
Program –
1. def inlist():
2. X = int(input("Enter number of values to be added in the list : "))
3. Y = []
4. for i in range (X):
5. print("Enter Element",i+1,": ",end="")
6. R = eval(input())
7. Y.append(R)
8. return Y
9. def Search(L1,X):
10. Postion = L1.index(X)+1
11. return Postion
12. List = inlist()
13. X = int(input("Enter The Element to be searched : "))
14. print("So ",X," is the Element ",Search(List,X),"in the list")
Output –
Enter number of values to be added in the list : 5
Enter Element 1 : 13
Enter Element 2 : 13
Enter Element 3 : 12
Enter Element 4 : 4113
Enter Element 5 : 1
Enter The Element to be searched : 1
So 1 is the Element 5 in the list
4. WAP where list of integers taken by user and Passing two
parameters list to function and number to be counted in the
list and return the number of occurrence of element in the
list.
Program –
1. def inlist():
Output –
Enter number of values to be added in the list : 5
Enter Element 1 : 12
Enter Element 2 : 13
Enter Element 3 : 23
Enter Element 4 : 23
Enter Element 5 : 23
Enter The Element to be counted : 23
So 23 is 3 times in the list
5. WAP where list of integers taken by user and Passing two
parameters list to function and number to be searched in the list
and return the position of element in the list. Program should be
menu driven.
Program –
1. def inlist():
2. X = int(input("Enter number of values to be added in the list : "))
3. Y = []
4. for i in range (X):
5. print("Enter Element",i+1,": ",end="")
6. R = eval(input())
7. Y.append(R)
8. return Y
9. def Search(L1,X):
10. Postion = L1.index(X)+1
11. return Postion
12. while True:
13. Code = int(input("Enter 1 : For Search \nEnter 2 : For Exit \nEnter Code : "))
14. if Code== 1:
15. List = inlist()
16. X = int(input("Enter The Element to be searched : "))
17. print("So ",X," is the Element ",Search(List,X),"in the list")
18. elif Code ==2:
19. print("Exiting Program...")
20. break
Output –
Enter 1 : For Search
Enter 2 : For Exit
Enter Code : 1
Enter number of values to be added in the list : 4
Enter Element 1 : 1
Enter Element 2 : 2
Enter Element 3 : 3
Enter Element 4 : 4
Enter The Element to be searched : 2
So 2 is the Element 2 in the list
Enter 1 : For Search
Enter 2 : For Exit
Enter Code : 2
Exiting Program...
11. WAP to remove all odd numbers from the given list.
(NOTE – Programs 6 to 10 where same as Program 1-5)
Program –
1. def inlist():
2. X = int(input("Enter number of values to be added in the list :
"))
3. Y = []
4. for i in range (X):
5. print("Enter Element",i+1,": ",end="")
6. R = eval(input())
7. Y.append(R)
8. return Y
9. def DelOdd(L1):
10. L2 = list(L1)
11. for i in L2:
12. if i % 2 != 0:
13. Y = L2.index(i)
14. del L2[Y]
15. return L2
16. L1 = inlist()
17. print(DelOdd(L1))
Output –
Enter number of values to be added in the list : 5
Enter Element 1 : 1
Enter Element 2 : 2
Enter Element 3 : 3
Enter Element 4 : 4
Enter Element 5 : 5
[2, 4]
1. def inlist():
2. X = int(input("Enter number of values to be added in the list : "))
3. Y = []
4. for i in range (X):
5. print("Enter Element",i+1,": ",end="")
6. R = eval(input())
7. Y.append(R)
8. return Y
9. def Second_Largest(L1):
10. Z = max(L1)
11. L2 = list(L1)
12. L2.remove(Z)
13. Y = max(L2)
14. return Y
15. L1 = inlist()
16. print("Second Largest Item is :",Second_Largest(L1))
Output –
Enter number of values to be added in the list : 7
Enter Element 1 : 134
Enter Element 2 : 1341
Enter Element 3 : 213
Enter Element 4 : 2133
Enter Element 5 : 1213
Enter Element 6 : 1231
Enter Element 7 : 1341
Second Largest Item is : 1341
Strings Program
1. Write a Python program using function to swap cases of a
given string passed as parameter.
Program –
1. X = input("Enter String : ")
2. print("Swap Case - ",X.swapcase())
Output -
Enter String : Hello World!
Swap Case - hELLO wORLD
Program –
3. def CountVowels(S):
4. Count = 0
5. for i in S:
6. if i in ("a","e","i","o","u"):
7. Count += 1
8. return Count
9.
10. S1 = input("Enter string : ")
11. print(CountVowels(S1))
Output -
Output –
Enter string : Hello World
No. of Words : 2
Program –
1. def Rev(S1):
2. Y = S1.split()
3. k =str()
4. for i in Y:
5. k += i[::-1] + " "
6. return k
7.
8. S1 = input("Enter string : ")
9. print("Reverse String (words) : ",Rev(S1))
Output –
Enter string : Hello World
Reverse String (words) : olleH dlroW
Output –
Enter string : Cooks are the best
Enter Character to be replaced : C
Enter Character to be placed : B
Books are the best
Dictionary Programs
1. Write a program to input names of in customers and their
details like items bought cost and phone number, store it in
dictionary and display all in a tabular form
Program -
1. def Input():
2. Name = input("Enter your name : ")
3. Mobile_no = input("Enter your Mobil no. : ")
4. Items = input("Enter your Items Bought : ")
5. Total_Cost = input("Enter Total cost of Item in Rs. : ")
6. L1 = [Total_Cost,Name,Items,Mobile_no,]
7. return Name,L1
8. Products = {"Santosh Kasana":["Rs. 300","Pocket Sanitizer",9191919191],"Virendre Singh":
["Rs. 900","Soap and Brush ",8989898989],}
9. X,Y = Input()
10. Products[X] = Y
11. L1 = ["SNO","Name","Total Cost","Items Purchased","Phone No."]
12. print("\n")
13. print(":"*126)
14. print('::',L1[0].center(5),"::",L1[1].center(27),"::",L1[2].center(20),"::",end='')
15. print(L1[3].center(29),"::",L1[4].center(24),"::")
16. print(":"*126)
17. Count = 1
18. for i in Products.keys():
19. print(':: ',Count,' ::\t',i,"\t",end='')
20. for k in Products[i]:
21. print('::\t',k,"\t",end = '')
22. print(' ::')
23. Count+=1
24. print(":"*126)
25. print("")
Output –
Output –
April
June
September
November
5. Write a program to input names of n employeesname and their
salary and display the name and salary of highest paid employees.
Program -
1. D1={"Ram":100000,"Shaam":200000,"Shyaam":150000}
2. N = int(input("Enter the inputs you want : "))
3. forii in range(N):
4. Name = input("Enter your name : ")
5. Salary = int(input("Enter your salary : "))
6. D1[Name]=Salary
7. K_Max = None
8. V_Max = 0
9. for i in D1:
10. if D1[i]>V_Max:
11. K_Max = i
12. V_Max = D1[i]
13. print(K_Max,"has",V_Max,"salary which is the highest.")
Output –
Enter the inputs you want : 2
Enter your name : Rakhi
Enter your salary : 100000
Enter your name : Vaishali
Enter your salary : 150000
Shaam has 200000 salary which is th highest.
6. WAP to Count the number of times a character appears in
a given string output should like
following Enter a string: HELLO WORLD
H:1
E:1
L:3
O:2
:1
W:1
R:1
D:1
Program -
1. D1 = {}
2. L1 = []
3. X = input("Enter String : ")
4. for i in X:
5. if i not in L1:
6. L1 += i
7. D1[i] = X.count(i)
8. for i in D1:
9. print(i," : ",D1[i])
Output –
Enter String : HELLO WORLD
H : 1
E : 1
L : 3
O : 2
: 1
W : 1
R : 1
D : 1
7. Write a Python script to generate and print a dictionary
that contains a number (between 1 and n) in
the form (x, x*x).
Program -
1. N = int(input("Enter the no. values : "))
2. D1 = {}
3. for i in range(1,N+1):
4. D1[i] = i*i
5. print(D1)
Output –
Enter the no. values : 5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Tuples Program
Q1) WAP that creates a tuple storing first 9 items of
Fibonacci Series.
Programs –
1. N=9
2. F=0
3. S=1
4. T1 = (F,S)
5. for i in range (N-2):
6. T=F+S
7. F=S
8. S=T
9. T1 += (T,)
10. print(T1)
Output –
(0, 1, 1, 2, 3, 5, 8, 13, 21)
Q2) WAP that creates a third tuple after adding two tuples.
Add second after first tuple.
Programs –
1. T1 = (1,2,3,4)
2. T2 = (4,5,6,7)
3. T3 = T2+T1
4. print("So Sum of Both tuples is ",T3)
Output –
So Sum of Both tuples is (4, 5, 6, 7, 1, 2, 3, 4)
Q3) WAP to calculate the mean of the numbers of the tuple.
Programs –
1. def Mean(T1):
2. L = len(T1)
3. Sum = 0
4. for i in T1:
5. Sum += i
6. Mean = Sum/L
7. return Mean
8. T1 = (1,3,5)
9. print(Mean(T1))
Output –
3.0
Output –
70.0
Q5) WAP to combine first 3 elements and last 3 elements
from a tuple
If t1=( 1, 2, 4 ,"a",6,6,8,9,","a",8,9,"y",",7,"L")
Output
( 1, 2, 4 ,"y",7,"L")
Programs –
1. T1 = (1,2,4,"a",6,8,9,"y",7,"L")
2. T2 = T1[0:3]+T1[-3::1]
3. print(T2)
Output –
( 1, 2, 4 ,"y",7,"L")
Module Program
File –
1. print("================== Math Friend ====================")
2. print("\nWelcome to the program of your personal Math Friend")
3. import Module
4. while True :
5. print("\nChoose From The Following - ")
6. print("Press 1 : Quadratic Equation Solver")
7. print("Press 2 : Fatorial Finder")
8. print("Press 3 : Reverse Number")
9. print("Press 4 : Prime Checker")
10. print("Press 0 : Exit")
11. Code = int(input("Enter The Function : "))
12. if (Code == 1):
13. Module.Quadratic()
14. elif (Code == 2):
15. Module.Factorial()
16. elif (Code == 3):
17. Module.Reverse()
18. elif (Code == 4):
19. Module.Prime()
20. elif (Code == 0):
21. break
22. else :
23. print ("Invalid Input")
Module
1. def Quadratic():
2. print("Welcome to Quadratic Equation Solver")
3. A = eval(input("Enter the value of A : "))
4. B = eval(input("Enter the value of B : "))
5. C = eval(input("Enter the value of C : "))
6. D = (B**2)-(4*A*C)
7. if D > 0 :
8. print("The roots of the equation are Distinct and Are Real
Number.")
9. Root_1 = -B+()
10. elif D == 0 :
11. print("The roots of the equation are Equal and Are Real
Number.")
12. elif D < 0 :
13. print("The roots of the equation are Complex Number.")
14. def Prime():
15. print("This Program is to Find if Number is Prime Or Not")
16. X=int(input("Enter The number : "))
17. Factor = 0
18. for i in range (2,(X//2)+1):
19. if (i!=0) and (X%i==0):
20. Factor +=1
21. if (Factor>0):
22. print("The Number is Composite")
23. elif(Factor==0):
24. print("The Number is Prime")
25. else:
26. print("Error")
27. def Reverse ():
28. print("\nThis program is Reverse Number ")
29. X = int(input("Enter The Number : "))
30. A=X
31. B=0
32. while (A!=0):
33. rem = A%10
34. B=B*10+rem
35. A=A//10
36. print("So reverse of The Number ",X," Is ",B)
37. def Factorial():
38. print("This program is to find Factorial of a Number : \n")
39. X=int(input("Enter The Number : "))
40. Factorial = 1
41. for i in range (1,X+1):
42. Factorial *= i
43. print("So, the Factorial of the number is ",Factorial)
Output
================== Math Friend ====================
SQL Program 1
Create the following tables with the Data Given
SHOPPE and ACCESSORIES
Table SHOPPE
ID SName Area
S001 ABC Computronics CP
S002 All Infotech Media GK II
S003 Tech Shoppe CP
S004 Greeks Tecno Nehru Place
S005 Hitech Tech Store Nehru Place
Table ACCESSORIES
No Name Price ID
A01 Mother Board 1200 S01
A02 Hard Disk 5000 S01
A03 Keyboard 500 S02
A04 Mouse 300 S01
A05 Mother Board 13000 S02
A06 Keyboard 400 S03
A07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard Disk 450 S03
Write the SQL Queries
(i) To Display Name and Price of all the ACCESSORIES in the
ascending order of their Price
Table ISSUES
Book_ID Qty_Issued
L02 13
L04 5
L05 21
Write the SQL Queries
(i) To show Book Name , Author Name and Price of books
ABC publisher