Certificate: Central Board of Secondary Education
Certificate: Central Board of Secondary Education
Principal: Teacher:
Mrs. Shalini Prajapati Mr. Alok Kanchan
Acknowledgement
count += 1 Output
WAP to Print Sum of n Natural Numbers
num = 16
if num < 0:
print("Enter a positive number")
else:
sum = 0
# use while loop to iterate un till zero
while(num > 0):
sum += num
num -= 1
print("The sum is",sum)
Output
WAP to Check No. is Odd or Even
Output
WAP to Find the Area of Triangle
a=5
b=6
c=7
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is:’,area)
Output
WAP to Check Whether No. is Positive,
Negative or 0
Output
WAP to Check Whether Input No. is Prime or
Not
num = 407
if num > 1:
for i in range(2,num):
if (num % i) == 0:
print(num,"is not a prime number")
print(i,"times",num//i,"is",num)
break
else:
print(num,"is a prime number")
else:
print(num,"is not a prime number")
Output
WAP to Find The Largest among Three Input
Numbers
num1 = 10
num2 = 14
num3 = 1
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number between" ,num1," ,",num2,
"and",num3,"is",largest)
Output
WAP to Check the Input year is a Leap Year or
Not
year = 2000
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
Output
WAP to Swap Two Variables
x=5
y = 10
temp = x
x=y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
Output
WAP to Find Factorial of a No.
num = 7
factorial = 1
if num < 0:
print("Sorry, factorial does not exist for negative
numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
Output
WAP to Check No. is Palindrome Or Not
n=int(input("Enter number:"))
temp=n
rev=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
Output
WAP to find Volume And Surface Area Of
Cuboid
Output
WAP to get Details of Students In Class
n=int(input(“Enter No.”))
def sum():
if n==1:
return 1
else:
n**2 + sum(n-1)
sum(n)
Output
WAP to Create Multiple Line Chart on a
Common Plot
import numpy as np
import matplotlib.pyplot as plt
Data=[[5,25,45,20],[8,13,29,27],[9,29,27,39]]
X=np.range(4)
plt.plot(X, Data[0],color=’b’,label=’range1’)
plt.plot(X, Data[1],color=’g’,label=’range2’)
plt.plot(X, Data[2],color=’r’,label=’range3’)
plt.legend(loc=’upper left’)
plt.title(“Multirange Line Chart”)
plt.xlabel(‘X’)
plt.ylabel(‘Y’)
plt.show()
Output
WAP to Create Multiple Line Chart on a
Common Plot
import numpy as np
import matplotlib.pyplot as plt
Data=[[5,25,45,20],[8,13,29,27],[9,29,27,39]]
X=np.range(4)
plt.plot(X, Data[0],color=’b’,label=’range1’)
plt.plot(X, Data[1],color=’g’,label=’range2’)
plt.plot(X, Data[2],color=’r’,label=’range3’)
plt.legend(loc=’upper left’)
plt.title(“Multirange Line Chart”)
plt.xlabel(‘X’)
plt.ylabel(‘Y’)
plt.show()
Output
WAP for Linear Searching in an Array
def search(list,n):
for i in range(len(list)):
if list[i] == n:
return True
return False
n = 'Geeks'
if search(list, n):
print("Found")
else:
print("Not Found")
Output
WAP for Binary Searching in an Array
else:
return binarySearch(arr, mid+1, r, x)
else:
return -1
Output
WAP to Plot Sin Cos Graph
import matplotlib.pyplot as plt
import numpy as np
x=np.arrange(0,10,0.1)
a=np.cos(x)
b=np.sin(x)
plt.plot(x,a,’b’)
plt.plot(x,b,’r’)
plt.show()
Output
WAP to Print String Backward
TABLE- BONUS
WORKER_REF_ID BONUS_DATE BONUS_AMOUNT
TABLE- TITLE
WORKER_REF_ID WORKER_TITLE AFFECTED_FROM
1 Manager 2016-02-20 00:00:00
2 Executive 2016-06-11 00:00:00
Table – EmployeeSalary
121 P1 8000
321 P2 1000
421 P1 12000
Ques.1. Write a SQL query to fetch the count of employees working in project
'P1'.
Ans. Here, we would be using aggregate function count() with the SQL where
clause-
SELECT COUNT(*) FROM EmployeeSalary WHERE Project = 'P1';
Ques.2. Write a SQL query to fetch employee names having salary greater
than or equal to 5000 and less than or equal 10000.
Ans. Here, we will use BETWEEN in the 'where' clause to return the empId of
the employees with salary satifying the required criteria and then use it as
subquery to find the fullName of the employee form EmployeeDetails table.
SELECT FullName
FROM EmployeeDetails
WHERE EmpId IN
(SELECT EmpId FROM EmpolyeeSalary
WHERE Salary BETWEEN 5000 AND 10000)
Ques.3. Write a query to fetch employee names and salary records. Return
employee details even if the salary record is not present for the employee.
Ans. Here, we can use left join with EmployeeDetail table on the left side.
SELECT E.FullName, S.Salary
FROM EmployeeDetails E LEFT JOIN EmployeeSalary S
ON E.EmpId = S.EmpId;
Ques.4. Write a SQL query to fetch all the Employees who are also managers
from EmployeeDetails table.
Ans. Here, we have to use Self-Join as the requirement wants us to analyze
the EmployeeDetails table as two different tables, each for Employee and
manager records.
SELECT DISTINCT E.FullName
FROM EmpDetails E
INNER JOIN EmpDetails M
ON E.EmpID = M.ManagerID;
Ques.5. Write a SQL query to fetch all employee records from
EmployeeDetails table who have a salary record in EmployeeSalary table.
Ans. Using 'Exists'-
SELECT * FROM EmployeeDetails E
WHERE EXISTS
(SELECT * FROM EmployeeSalary S WHERE E.EmpId = S.EmpId);
Ques.6. Write a SQL query to fetch duplicate records from a table.
Ans. In order to find duplicate records from table we can use GROUP BY on
all the fields and then use HAVING clause to return only those fields whose
count is greater than 1 i.e. the rows having duplicate records.
SELECT EmpId, Project, Salary, COUNT(*)
FROM EmployeeSalary
GROUP BY EmpId, Project, Salary
HAVING COUNT(*) > 1;
Ques.7. Write a SQL query to remove duplicates from a table without using
temporary table.
Ans. Using Group By and Having clause-
DELETE FROM EmployeeSalary
WHERE EmpId IN (
SELECT EmpId
FROM EmployeeSalary
GROUP BY Project, Salary
HAVING COUNT(*) > 1));
Ques.8. Write a SQL query to fetch only odd rows from table.
Ans. This can be achieved by using Row_number in SQL server-
SELECT E.EmpId, E.Project, E.Salary
FROM (
SELECT *, Row_Number() OVER(ORDER BY EmpId) AS RowNumber
FROM EmployeeSalary
)E
WHERE E.RowNumber % 2 = 1
Table Name:- Employee
Empid EmpName Department ContactNo EmailId EmpHeadId
Principal:
Teacher:
Examiner: