You are on page 1of 7

# 1 question : Write a program to demonstratestring and list indexing using

function Indexing().

def indexing():
a2=[12,'hello',26,53]
for x in range (len(a2)-1,-1,-1):
if x==1:
for y in range (len(a2[x])-1,-1,-1):
print(a2[x][y])
else:
print(a2[x])

indexing()

# 2 question : Write a program to demonstrate tuple and dictionary using for loop.

a2={1:(12,43,53),2:(22,"four",21)}
for x in a2.values():
for y in x:
print(y)

# 3 question : Write a program to demonstrate the use of jumping statement.

a=0
while 10>a:
if a<5:
print(a)
elif a==5:
print(a*a)
a=a+1
continue
elif a>5 and a<9:
print("remaining is :",a)
else:
break
a=a+1

# 4 question : Write a program to print pattern


## *
## **
## ***
## ****
## *****

for x in range (6):


for x in range (6):
print('*',end=' ')
print()

# 5 question : Write a program to read a string from user input and tell the no. of
uppercase and lowercase letters.

def readstring():
a1=input('enter upper and lower case text :\n')
upper=lower=0
for i in a1:
if i.isupper():
upper+=1
else:
lower+=1
print('no. of uppercase :',upper,
'\n','no. of lowercase :',lower)

readstring()

# 5 question : Write program to find the factorial of any given no.

def Factorial():
a1=int(input('Enter the no. :'))
s=1
for x in range (a1,0,-1):
s=s*x

print("the factorial is :",s)

Factorial()

# 6 question : Write a program to demonstrate global and local kwywords.

def s1():
global w1
w1=50
print("local keyword :",w1)

w1=5
print("global keyword :",w1)
s1()

# 7 question : Write a program to demonstrate the use of variable length argument.

def var_len_arg(a,*b):
print('simple argument :',a)
print('variable length argument :',b)

var_len_arg(3,'hello',62,43535,[43,565])

# 8 question : write a program to demonatrate the use of return statement in a


loop.

def retu():
b=0
a=[]
while 30>b:
if b>15:
return a
else:
a.append(b)
b+=2
s1=retu()
print(s1)

# 9 question : Write a program which take integer from user and print all the
numbers separtally .

s1=input('enter the no.. :')

for x in s1:
print(x,end=' ')

# 10 question : write a program while tells the no. of zeros in a program.

a1=input('enter the no. :')


zero=0
for x in a1:
if x=='0':
zero+=1

print('number of zeros in this no. :',zero)

# 11 question : write a program which updates data in text file.

def write_txt():
a1=open("read_file.txt",'w+')
print(a1.read())
yes='y'
while yes=='y':
d1=input('enter name :')
d2=input('enter roll no. :')
d3=input('enter class :')
t=[d1,d2,d3]
a1.write('hrllo')
yes=input('y/n :')
print(a1.read())
a1.close()

write_txt()

# 12 question : write a program which reads data from text file.

def read_txt():
a1=open("read_file.txt",'r')
k=a1.read()
print(k)
a1.close()
read_txt()

# 13 question :Write a program which updates data in binary file .

from pickle import *

def write_bin():
with open('rt.bin','wb') as f:
dump('hello',f)

write_bin()

# 14 question :write a program which reads data from binary file.


from pickle import *
def read_bin():
with open('rt.bin','rb') as f:
while True:
try:
s=load(f)
print(s)
except:
break

read_bin()

# 15 question : write a program which update data in CSV file.

from csv import *

def write_csv():
with open(r"C:\ft.csv",'w') as f:
w1=writer(f)
w1.writerow([54,56,5,65,'hello'])

write_csv()

# 16 question : write a program which reads data from CSV file.

from csv import *

def read_csv():
with open(r"C:\ft.csv",'r') as f:
r=reader(f)
for x in r:
print(x)
read_csv()

# 17 question : write a program which updates roll no. of 10 students in stack.


from random import*
def stack():
a=[]
for x in range (10):
s=randint(1,100)
a.append(s)
print('data of 10 students is :\n',a)

stack()

# 18 write a program which remove data from stack until overflow of stack.

def remov():
a=[34,3,4]
for x in range (len(a)+1):
if a==[]:
print('stack overflow ')
else:
print('removing ',a.pop(-1))

remov()

# 19 question : write a program which reads data from top of stack.

def read_stack():
a=[23,62,53,26]
if a==[]:
print('stack overflow')
else:
print('the top element is :',a[-1])

read_stack()

# 20 question : print a isoselous triangle pattern using for loop.


a=1
for x in range (6,-1,-1):
print(' '*x*2,'#'*a*2)
a+=2

# 21 question : print a X pattern using while loop.


x=0
while x<6:
print(' '*x,'*',' '*(5-x)*2,'*')
x=x+1
print(' '*6,'*')
x=5
while x>-1:
print(' '*x,'*',' '*(5-x)*2,'*')
x=x-1

# 22 question : write a program which demonstrate the use of show and create and
drop command in SQL.

show databases;

create database school ;

drop database school;

# 23 question : write a program which creates a database "office" and creates a


table "year2022" and use following details
id_number = int()
name_workers = char()
Date =DOB
phone_no = int()
address = varchar()

create database office;

use office;

create table year2022 (id_number int primary key,


name_workers char(30) ,
DOB Date ,
phone_no int ,
address varchar(100) );

# 24 question : write a command which describes the table "year2022" and operte
following opertaions.
a) drop { phone_no }
b) change { name_workers to emp_name }
c) modify address { not null }
d) rename table { office to office_2022 }
e) add column { age - not null int }
f) delete a table

<1> alter table year2022 drop phone_no;

<2> alter table year2022 change name_workers emp_name ;

<3> alter table year2022 modify address not null;

<4> alter table year2022 rename to office_2022;

<5> alter table year2022 add age not null int ;

<6> drop table year2022;

# 25 question : write a program which creates a database "school" and creates a


table "record" and use following details
id_no = int()
name = char()
Date =DOB
marks = float(3,2)
address = varchar()

create database school;

use school;

create table record(id_no int primary key,


name char(30),
DOB date ,
marks float(3,2),
address varchar(50));

# 26 write a program which insert following data

<1> { 12 , 'karan' , 3-4-2005 , 54.3232 , defence colony }


<2> { 13 , 'aman' , 1-6-2006 , 84.3232 , home }
<3> { 14 , 'ram' , 8-3-2005 , 74.3232 , navin colony }

a) insert into record values( 12 , 'karan' , 3-4-2005 , 54.3232 , defence colony );


b) insert into record values( 13 , 'aman' , 1-6-2006 , 84.3232 , home );
c) insert into record values ( 12 , 'ram' , 8-3-2005 , 74.3232 , navin colony );
# 27 question : write a program which update following data in table 'record'

<1> marks=54.3232 to marks= 91.82


<2> name= ram to ramesh
<3> id_no=12 to id_no=15

a) update record set marks=91.82 where marks=54.3232;


b) update record set name='ramesh' where name='ram';
c) up[date record set id_no=15 where id_no=12;

You might also like