0% found this document useful (0 votes)
5 views11 pages

PY Exam

The document contains a series of Python code snippets demonstrating various programming concepts such as lists, tuples, sets, dictionaries, functions, classes, and control flow. It includes examples of operations on data structures, function definitions, and usage of libraries like math and random. Additionally, it showcases GUI creation with Tkinter and basic input/output operations.
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)
5 views11 pages

PY Exam

The document contains a series of Python code snippets demonstrating various programming concepts such as lists, tuples, sets, dictionaries, functions, classes, and control flow. It includes examples of operations on data structures, function definitions, and usage of libraries like math and random. Additionally, it showcases GUI creation with Tkinter and basic input/output operations.
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/ 11

Q.

7
l1=[10,20,30]
print(l1)
print(l1[1])
l1.append(40)
print(l1)
del l1[1]
print(l1)
Q.8
l1=[10,20,30]
print(l1)
l2=[50,60]
print(l2)

print(len(l1))
print(max(l1))
print(min(l1))
print(l1.extend(l2))
print(l1.count(10))
print(l1.pop())
print(l1.reverse())
print(l1.sort())
print(l1.append(40))
Q.9
t1=(10,20,30,40)
print(t1[1])
print(t1)
l1=list(t1)
print(l1)
del t1

Q.10
s={10,20,30,40}
print("Set is",s)
for i in s:
print(i)
s.add(50)
s.discard(10)
print("Set is",s)

Q.11
s1={10,20,30,40}
s2={10,20,50,60}
u=s1.union(s2)
i=s1.intersection(s2)
d=s1.difference(s2)
sd=s1.symmetric_difference(s2)
print(u)
print(i)
print(d)
print(sd)

Q.13
d1={1:10,2:20,3:30}
print(d1[1])
d1[4]=40
del d1[1]
for key,value in d1.items():
print(key,'-',value)
Q.14
def fun():
a=10
b=20
print("Adition :",a+b)
def fun1(a,b):
print("Adition :",a+b)
def fun2(a,b):
return a+b
fun()
fun1(10,20)
print(fun2(10,20))

Q.15
def name(name,age):
print("hi i am ",name)
print("Age is ",age)
name('atharva',20)
name(20,'siddhi')
def nameage(name,age):
print("hi i am ",name)
print("Age is ",age)
nameage(age=20,name='Atharva')
nameage(name='siddhi',age=20)
def dename(fname,mname,lname='shinde'):
print("My name is ",fname,mname,lname)
dename('atharva','shashikant','shinde')
dename('siddhi','atharva','jitkar')
dename('siddhi','atharva')
def total(*args):
tot=0
for i in args:
tot=tot+i
return tot
add=total(5,6,7,8)

Q.16
x=lambda a,b,c:a+b-c
print(x(19,1,8))

a=['1','2','3','4']
res=map(int,a)
print(list(res))

from functools import reduce


a=[10,20,30,40]
res1=reduce(lambda x,y:x+y,a)
print(res1)

Q.17
def read():
name=input("Enter name")
rollno=int(input("Enter roll no"))
address=input("Enter address")
clgname=input("Enter clg name")
div=input("Enter division")
print("Name :",name,"\tRoll no :",rollno)

import mod
mod.read()

Q.18
import math,os,random
print(math.sqrt(5))
print(math.ceil(4.3))
print(math.pow(2,3))
print(os.getcwd())
print(os.listdir())
print(os.mkdir("exam123.py"))
print(random.randint(10,20))
print(random.random())
colour="red","blue","green"
print(random.choice(colour))

Q.19
def operation(a,b):
print(a+b)
print(a*b)
print(a/b)
print(a-b)
from Mypack1 import mod
mod.operation(10,20)

Q.20
class stu:
def dec(self):
print("hello")
s=stu()
s.dec()

Q.21
class Ex1:
def __init__(self):
a=int(input("Enter: "))
b=int(input("Enter: "))
print("addition: ",a+b)
e=Ex1()
class Ex1:
def __init__(self,a,b):
print("addition: ",a+b)
e=Ex1(10,20)

class Ex1:
def __init__(self,name='Unknown',age=0):
self.name=name
self.age=age
def disp(self):
print("hi my name is ",self.name,"I am ",self.age,"year
old")
e=Ex1()
e1=Ex1('Atharva')
e2=Ex1('Atharva',20)
e.disp()
e1.disp()
e2.disp()

Q.22
class Ex1:
def area(self,l=0,b=None):
if b is None:
print("AOS :",l*l)
else:
print("AOR :",l*b)
e=Ex1()
e2=Ex1()
e.area(5)
e2.area(19,1)

class Degree:
def getDegree(self):
print("I got a degree")
class Undergraduate:
def getDegree(self):
print("I got a Undergraduate")
class Postgraduate:
def getDegree(self):
print("I got a Postgraduate")
d=Degree()
u=Undergraduate()
p=Postgraduate()
d.getDegree()
u.getDegree()
p.getDegree()

Q.23
class stud:
def read(self):
name='Atharvawd'
class stud1(stud):
def read1(self):
roll=20
class disp(stud1):
def out(self):
print("name :",name,"roll no. : ",roll)
d=disp()
d.read()
d.read1()
d.out()

Q.24
import tkinter as tk
root=tk.Tk()
root.title("Register")
tk.Label(root,text="Name").pack()
tk.Entry(root).pack()
tk.Label(root,text="Password").pack()
tk.Entry(root,show="*").pack()
tk.Button(root,text="Register").pack()
root.mainloop()

Q.25
n=5
f=1
for i in range(1,n+1):
f *= i
print(f)

Q.26
for i in range(1,101):
if i%2==0:
print("Even: ",i)
else:
print("Odd: ",i)

Q.27
for i in range(1,10):
if i==5:
break
print(i)
for i in range(1,10):
if i==5:
continue
print(i)

Q.28
a=[1,3]
b=[2,4]
print(a+b)

Q.29
a=19
b=21
print(a)
print(b)
c=a
a=b
b=c
print(a)
print(b)

Q.30
y=2012
if y%4==0:
print("leap year")
else:
print("mpt")
a=19
if a>=18:
print("Vote")
else:
print("not")

Q2
a=10
b=5
print(a+b,a-b,a/b,a*b)
print(a>b and a!=b)
print(a>b and a==b)
a *= 2
b += 2
print(a,b)

Q.3
a=10
b=5
print(a&b,a|b,a<<2,a>>2)
l1=[10,20,30]
print(a is b)
print(a is not b)
print(10 in l1)
print(40 not in l1)

Q.4 a=10
if a%2==0:
print("Evemn no.")
else:
print("Odd number")
b=12
if b%2==0:
if b%3==0:
print("botyh")
else:
print("By 2")
else:
print("By none")

Q.5
g=80
if g>=95:
print("First class")
elif g>=80 and g<95:
print("Secopnjd clasas")
elif g>=60 and g<80:
print|("Thjirfd class")
elif g>=35 and g<60:
print("pass")
else:
print("Faiul")

Q.6
for i in range(1,10):
print(i)
i=0
while i<5:
print(i)
i=i+1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy