0% found this document useful (0 votes)
25 views

Computer Science Practical File

The document contains examples of Python programs that demonstrate taking user input, printing output, performing calculations like finding average and largest number, and using SQL queries to create and populate a database table. The programs cover basic concepts like conditional statements, loops, lists, and database operations.

Uploaded by

queenslover2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Computer Science Practical File

The document contains examples of Python programs that demonstrate taking user input, printing output, performing calculations like finding average and largest number, and using SQL queries to create and populate a database table. The programs cover basic concepts like conditional statements, loops, lists, and database operations.

Uploaded by

queenslover2023
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPUTER SCIENCE PRACTICAL FILE

1. WAP to input a digit and print it in words.

INPUT:

n=int(input("Enter the digit from 0 to 9:"))

print("Entered digit is:",end='')


if n ==0:
print("Zero")
elif n==1:
print("One")
elif n==2:
print("Two")
elif n==3:
print("Three")
elif n==4:
print("Four")
elif n==5:
print("Five")
elif n==6:
print("Six")
elif n==7:
print("Seven")
elif n==8:
print("Eight")
elif n==9:
print("Nine")
else:
print("Not a digit")

OUTPUT:
Enter the digit from 0 to 9:9

Entered digit is: Nine

2. WAP to find the average of the list of the numbers


entered through keyboard.

INPUT:

n=int(input("Enter the limit:"))

s=0
for i in range(1,n+1):
print("Enter",i,end='')
a=int(input("th number:"))
s=s+a
avg=s/n
print("The sum of entered numbers:",s)
print("The average of entered numbers:",avg)

OUTPUT:

Enter the limit:7


Enter 1th number:3
Enter 2th number:4
Enter 3th number:2
Enter 4th number:4
Enter 5th number:5
Enter 6th number:3
Enter 7th number:5
The sum of entered numbers: 26
The average of entered numbers: 3.7142857142857144
3. WAP to find the 2nd largest number from the list of the
numbers entered through keyboard.

INPUT:

a= []

n= int(input("Enter number of elements:"))


for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Second largest element is :",a[n-2])

OUTPUT:

Enter number of elements: 4

Enter element: 3
Enter element: 2
Enter element: 1
Enter element: 0
Second largest element is: 2

4. Create a table using MySQL Queries.(include insert and


select)

INPUT:
-- create
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL
);

-- insert
INSERT INTO EMPLOYEE VALUES (0001,
'Clark', 'Sales');
INSERT INTO EMPLOYEE VALUES (0002,
'Dave', 'Accounting');
INSERT INTO EMPLOYEE VALUES (0003, 'Ava',
'Sales');

-- fetch
SELECT * FROM EMPLOYEE WHERE dept =
'Sales';

OUTPUT:

+-------+-------+-------+
| empId | name | dept |
+-------+-------+-------+
| 1 | Clark | Sales |
| 3 | Ava | Sales |
+-------+-------+-------+

You might also like