0% found this document useful (0 votes)
22 views17 pages

Py Project t2

The document contains 15 questions related to Python programming concepts like lists, tuples, dictionaries, SQL queries, etc. Each question provides sample source code to solve the given problem and expected output. The questions cover topics like finding maximum and minimum values in a list, sorting lists, reversing lists, counting even/odd numbers, retrieving values from dictionaries using keys, performing arithmetic operations on list elements based on conditions, creating and manipulating databases and tables, and more.

Uploaded by

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

Py Project t2

The document contains 15 questions related to Python programming concepts like lists, tuples, dictionaries, SQL queries, etc. Each question provides sample source code to solve the given problem and expected output. The questions cover topics like finding maximum and minimum values in a list, sorting lists, reversing lists, counting even/odd numbers, retrieving values from dictionaries using keys, performing arithmetic operations on list elements based on conditions, creating and manipulating databases and tables, and more.

Uploaded by

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

S.

NO PROGRAM REMARK
S
1 Print highest and lowest
2 Ascending & descending
3 Reverse order
4 Counting no. of positive
and negative values in
tupple
5 Counting no. of even and
in tupple
6 Dictionary (Printing
phone no.)
7 Phone no. of friend name
aman in dictionary
8 Add 2 to even and 3 to
odd in list
9 NO. IN REVERSE Count
no. of even values in list
10 Print first and last
element in list
11 Add 1 to even and 2 to
odd
12 SQL 1
13 SQL 2
14 SQL 3
15 SUM OF NO.S DIVISIBLE
BY 5
Q.1 WAP a program to input 10 elements in a list .
Print the highest and second highest number.

Source code:
L=[]
for i in range(10):
n=int(input("enter a number:"))
L.append(n)
a=max(L)
print("highest number is:",a)
L.remove(a)
print("second highest number is:",max(L))

Output:
Q.2 WAP to input n elements in a list. Print the list in
ascending and descending order.

Source code:
L=[]
n=int(input("enter no of elements:"))
for i in range(n):
e=int(input("enter elements:"))
L.append(e)
L.sort()
print("ascending order:",L)
L.sort(reverse=True)
print("descending order:",L)
Output:
Q.3 WAP to input n elements in a list. Print the list in
reverse order.

Source code:
L=[]
n=int(input("enter no of elements:"))
for i in range(n):
e=input("enter elements:")
L.append(e)
L.reverse()
print(L)

Output:
Q.4 WAP to input n elements in a tuple.Count and
print positive,negative and zeroes entered.

Source:
n=int(input("enter no of elements:"))
t=()
for i in range(n):
num=int(input("enter a number:"))
t=t+(num,)
print(t)
c=0
m=0
k=0
for j in t:
if j>0:
c=c+1
elif j<0:
m=m+1

else:
k=k+1
print("positive numbers entered are:",c)
print("negative numbers entered are:",m)
print("zeroes entered are:",k)

Output:
Q.5 WAP to input 10 elements in a tuple count and
print even numbers entered.

Source:
t=()
c=0
for i in range(10):
n=int(input("enter a number:"))
t=t+(n,)
for j in t:
if j%2==0:
c=c+1

print("total even numbers entered are:",c)


Output:
Q.6 WAP to create a dictionary named friend with 5
key values, display phone no of friend placed at
second number.

Source:
friend={}
for i in range(5):
name=str(input("enter a name:"))
phono=int(input("enter a phone number:"))
friend[name]=phono
a=friend.values()
b=list(a)
print(b[1])

Output:
Q.7 WAP to create a dictionary named directory with
having n values as name and phone no . Print the
phone no of all users stored with the name “aman”.

Source:
directory={}
for i in range(5):
name=str(input("enter name:"))
phono=int(input("enter phono:"))
directory[name]=phono
a="aman"
if a in directory:
print(directory.get(a))

Output:

Q.8 Write a program to input a list of 10 nos add 2 to


all even nos and 3 to all odd nos.
Source:
l=[]
for i in range(5):
n=int(input("enter a no"))
l.append(n)
for i in range(5):
if l[i]%2==0:
l[i]=l[i]+2
else:
l[i]=l[i]+3
print(l)
Output:

Q.9 WAP to input a number from the user. Print the


number in reverse.
Source:
n=int(input("enter a number"))
b=str(n)
print(b[::-1])
Output:

Q.10 WAP a program to input 10 numbers in a list.


Remove the first and last element from the list and
print the list.
Source code:
L=[]
for i in range(10):
n=int(input("enter a number:"))
L.append(n)
L.pop(0)
L.pop(-1)
print(L)
Output:

Q.11 WAP a program to input n numbers in a list add


1 to all elements stored at odd position and add 2 to
all no.s at even position.

Source code:
L=[]
n=int(input("enter no of elements you want to add:"))
for i in range(n):
num=int(input("enter a number:"))
if i%2!=0:
num=num+1
else:
num=num+2
L.append(num)
print(L)

Output:

Q.12
1)Write a command to create table member with all fields
and constraints , member id , member name ,type of
membership , mobile no .
Create table member
(member_id int primary key,member_name varchar(30) not null ,
type_of_membership varchar(50), mobno char(10));
2)Write a command to display the structure of the table
Desc member ;
3)Write a command to add a new column membership fee
Alter table member Add memfee float(10,2);
4)Write a command to change the size of the column TOM to
varchar(50) and not null Alter table member
Modify type_of_membership varchar(50) Not null;
5)Write a command to remove column TOM from the table
Alter table member Drop type_of_membership;
6)Write a command to add a record in the member
Alter table member Insert into member Values (1,”ayush”,’8382727360”,7000);
7)Write a command to display all commands from the table
member
Select * from member;

Q.13
1)Write a command to create database voter
Create database voter;
2)Command to display all databases
Show databases;
3)Create table named data with the following fields VID
(primary key),V name, DOB, address
Create table data(Vno int primary key, vname varchar(30),DOB date, address
varchar(30));
4)Display the structure of voter table
Desc voter;
5)Add a new column named annual income in the voter
table
Alter table voter Add A_income int;
6)Modify the size of vname column as varchar(50)
Alter table voter Modify vname varchar(50);
7)Add any 5 records in the voter table
Insert into voter Values (1,”ayush”,”2006-12-6”,”sector-61”,7000);
8)Display Vid and Vname of all the voters
Select Vid,Vname from voter;
9)Display the details of all the voters whose income is more
than 2 lakh
select* from voter Where A_income>200000;

Q.14

1)Create a database client


Create database client;
2)Open database client
Use client,
3)Create a table employee using following fields
Eno,Ename,Job,DOJ,mobileno.
Create table employee (Eno int primary key, Ename varchar(30),Job
varchar (30),DOJ date,mobno char(10) not null) ;
4)Display structure of the employee table .
Desc employee;
Add a new column DOB
Alter table employee Add DOB date;
5)Increase the size E.name column varchar(50)
Alter table employee Modify Ename varchar (50);
6)Add a new column salary in the above table
Alter employees Add salary float;
7)Store 10000 in the salary column of all employees
Update employees Set salary=10000 ;
8)Display all the records of the employee whose job
is manager
Select * from employee Where job = “manager”;
Q.15 WAP to input 10 numbers print the sum of all
numbers divisible by 5.

Source:
L=[]
for i in range(10):
n=int(input("enter a number:"))
L.append(n)
c=0
for j in L:
if j%5==0:
c=c+j
print("sum of numbers divisible by 5 is:",c)
Output:

You might also like