0% found this document useful (0 votes)
4 views13 pages

Computer Science

The document contains a computer science project by Shail A. Patel, showcasing various Python and SQL programming exercises. It includes code snippets for tasks such as reversing numbers, checking for Armstrong numbers, greeting users based on gender and time, and performing SQL queries on employee and department tables. The project demonstrates programming concepts and practical applications in both Python and SQL.

Uploaded by

shailpatel2323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views13 pages

Computer Science

The document contains a computer science project by Shail A. Patel, showcasing various Python and SQL programming exercises. It includes code snippets for tasks such as reversing numbers, checking for Armstrong numbers, greeting users based on gender and time, and performing SQL queries on employee and department tables. The project demonstrates programming concepts and practical applications in both Python and SQL.

Uploaded by

shailpatel2323
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPUTER SCIENCE

PROJECT
PyThON & SQL

• NAME :- ShAIL.A.PATEL
• CLASS :- 11 SCI
Th

• ROLL :- 29
FILE RECORD
(PyThON)
• Programme :
Q. Accept a number and reverse it.
n = int(input('Enter

number:')) rev = 0 while n > 0:

r = n%10 n = n//10 rev

= 10*rev + r print(rev)

Q. Accept a number and and print the sum of its digit in single digit.
#Code:
n = int(input('Enter number:'))

while n > 9: s = 0

while n > 0: r = n%10

n = n//10 s += r n

= s

print(n)

Q. Accept a number and check for armstrong.


#Code:

n = int(input('Enter number:'))

c=ns=0

while n > 0:

r = n%10

n = n//10

s = r**3+s if s == c:

print('It is an Armstrong')
else:

print('It is not an Armstrong')

Q. Write a code to input name,gender,current time and greet them.

a=input('Enter your name>>>>>')

b=input('Enter your gender

male/female>>>>>')

c=float(input('Enter Current time in

the form of HH.MM in 24 hour

format >'))

if b=='male': if c<=12.00:

print('Good Morning',a,'sir') else:

print('Good Afternoon',a,'sir') else: if

c>=12.00:

print('Good Morning',a,'madam')

else: print('Good

Afternoon',a,'madam')

Q. Accept name, roll number and marks of subjects and print its result.

n=input('Enter your name:')

mkseng=float(input('Enter your

english marks:'))

mksmat=float(input('Enter your math

marks:'))
mkssci=float(input('Enter your science

marks:'))

mksss=float(input('Enter your social

studies marks:'))

mit=float(input('Enter your Information

Technology marks:'))

mt=(meng+mmat+msci+mss+mit)/5

if mt>=91:

print('Total Percentage-',mt,'Grade-A1')

elif mt>=81:

print('Total percentage-',mt,'Grade-A2')

elif mt>=71:

print('Total percentage-',mt,'Grade-B1')

elif mt>=61:

print('Total percentage-',mt,'Grade-B2')

else:

print('Total percentage-',mt,'Grade-E')

Q. Write a code for Fibonacci series.

x=int(input('Enter the numbers you

want to have in the series: ')) a=0


b=1 print(a,b,end =' ') for i in range(x-

2):

c=a+b a,b=b,c print(c,end=' ')

Q. Write a code to check wether the given number is prime or not.

num=int(input('Enter your value: '))


if num>1:
for i in range(2,int(num/2)+1):
if num%i==0:
print(num, 'is not a prime number') break
elif:
print(num,'is a prime number')
elif:
print(num,'is not a prime number')
Q. Write a code to print |[{a+e2/5+log1030}1/2]| Using the math function.

import math as m

x=m.fabs(m.sqrt((a+

m.exp(e,2)/(5+m.log(30)))))

print(x)

STRING
Q. Accept a string and check how many times the letter ‘A’ exist.
#Code:
s=input('Enter your string:

') l=len(s) c=0 for i in

range(l): if s[i]=='A':

c=c+1 print(c)
Q. Accept a string and the number of vowels present in the string.

s=input('Enter your string: ') l=len(s) c=0 for i in

range(l): if s[i] in

['A','E','I','O','U','a','e','i','o','u']:

c=c+1

print(c)

Q. Write a code to find the position of first occurrence of a letter in given string.
S=input("Enter a string:-")
ch=input("Enter the character to find:-")
i=0
for i in range(len(S)):
if S[i]==ch:
print(i+1) break
else:
print("Character not found")
Q. Accept a String/Paragraph and a character and find how many times this character
exist in the String/Paragraph.
s = input("Enter string: ")
x = input("Enter character: ")
c=0
for i in s:
if x == i:
c += 1 if c != 1:
print(x, "exist", c, "times")
else:
print(x, "doesn’t exist")
Q. Accept a String/Paragraph and a character and remove that character in the
String/Paragraph.
s = input("Enter string: ") c

= input("Enter character: ") x

= '' for i in s: if i !=

c: x += i print(x)

Q. Accept a string and check whether its palindrome or not.

S = input("Enter String :")

if S == S[::-1]:

print("It is Palindrome")
else: print("It is not
Palindrome")

Q. Accept an address and display the sum of digits appearing in it.

s=input('Enter a address: ')


For i in range(len(a)):
If s[i]>='0'and s[i]<='9':
k=k+int(s[i])
print(k)
Q. Accept a string and replace lowercase to uppercase, uppercase to ‘#’
and digit to ‘$’.

s=input('Enter a string: ')


l=list(s)
For i in
range(len(l)): If
l[i].islower():
l[i].upper() If
l[i].isupper:
l[i]='#' If
l[i].isdigit():
l[i]='$'
s=''.join(l)
print(s)
Q. Accept a string and check whether its palindrome or not.

S = input("Enter String :")

if S == S[::-1]:

print("It is Palindrome")
else: print("It is not
Palindrome")

PATTERN PRINTING
#Pattern 1:
for r in range(1,5):

for c in range(1,5):

print('*',end=' ') print()

Output:
* * * *

* * * *

* * * *

* * * *

#Pattern 2:
for r in range(1,5): for c

in range(1,r+1):

print('*',end=' ') print()

Output:
*

* *

* * *
* * * *
#Pattern 3:(Decreasing Triangle)
for r in range(1,5): for c

in range(r,5):

print('*',end=' ') print()

Output:
****

***

**

#Pattern 4:(Hill Pattern)


for r in range(4): for c in

range(r,4): print('

',end=' ') for c1 in

range(r):

print('*',end=' ') for c2

in range(r+1):

print('*',end=' ') print()

Output:
*

* * *

* * * * *
NUMBER PATTERN
#Pattern 1:
for r in range(1,5): for c

in range(1,r+1):

print(‘1’,end=" ") print()

Output:
1

1 1

1 1 1

1 1 1 1

#Pattern 2:
for r in range(1,5): for c

in range(1,r+1):

print(c,end=" ") print()

Output:
1

1 2

1 2 3

1 2 3 4

#Pattern 3:
for r in range(4,0,-1): for
c in range(1,r+1):
print(c,end=" ") print()

Output:
1 2 3 4

1 2 3

1 2

#Pattern 4:
for r in range(1,5): for c in

range(1,5-r): print("

",end=" ") for b in

range(1,r+1):

print(b,end=" ") for p in

range(r-1,0,-1):

print(p,end=" ") print()

Output:
1

1 2 1

1 2 3 2 1

1 2 3 4 3 2 1

#Pattern 5:
r = int(input('Enter number of rows required: '))

for i in range(r): for j in

range(r-i): print(' ',

end='')

for j in range(2*i+1):

if j==0 or j==2*i or i==r-1:

print('1',end='') else:

print(' ', end='') print()


SQL
Table: Emp
ENo Enm Sal DOJ Dpno
001 Rajendra 20,000 10-3-2021 2
002 Vijayraj 40,000 15-7-2020 3
003 Anand 15,000 3-8-2022 1
004 Devraj 60,000 6-1-2019 4
005 Kapil 50,000 1-4-2019 1

Table: Dpt
dpno Dnm floor
1 acc 2
2 edp 3
3 pkg 1
4 sales 4

Queries:
Q. Display total number of employes working in account department.
Ans: Select count(enm) from emp where dpno = (select dpno from

dpt where dnm='acc');

Q. Find maximum and minimum salary of each department wise along with their names.

Ans: Select max(sal),mi(sal),dnm from emp,dpt where

emp.dpno=dpt.dpno group by dnm;

Q. Increase the salary of edp departments employees by 1500.

Ans: Update emp set sal=sal+1500

where dpno in (Select dpno from dpt where dnm='edp')

Q. Display all the employees name whose salary is less than 20,000 whose name starts with ‘A’.
Ans: Select enm from emp where sal<500 and

enm like 'A%';

Q. Display all employees info whose salary is not yet decied.


Ans: Select * from emp where sal

is null:

Q. Display department name who belongs to second floor except edp.

Ans: Select dnm from dpt where floor=2

and dnm!='edp';

Q. Dispaly employees name,department number and floor in which ‘a’ character is exist in the
department name.

Ans: Select enm,emp.dpno,floor from emp,dpt where

dpt.dnm like '%a%';

Q. Display department name and their expenses of salary in highest to lowest order.

Ans: Select dpt.dnm,sum(emp.sal) from emp,dpt where

dpt.dpno=emp.dpno group by dnm order by

sum(sal);

Q. Display employee ,name and experience.

Ans: Select enm,year(curdate())-year(doj) from emp; Q.


Display name and this annual salary.

Ans: Select enm,sal*12 as annual salary from emp;

You might also like