Q1= Write a Python program to accept n numbers in list and remove
duplicates from a list.
str = input("enter the string:")
def calculate():
uppercase = 0
lowercase = 0
for ch in str:
if [Link]():
uppercase = uppercase + 1
else:
lowercase = lowercase + 1
print("lowercase character is :",lowercase)
print("uppercase character is :",uppercase)
calculate()
Output:
Enter the number of elements in list:4
Enter element1:10
Enter element2:20
Enter element3:30
Enter element4:10
Non-duplicate items:
[10, 20, 30]
Q2=Write a Python function that accepts a string and calculate the number of
upper case letters and lower case letters.
List=input("enter the list:")
def remove(List):
finallist=[]
for num is List:
if num not in finallist:
[Link](num)
print(finallist)
List=[1,2,3,4,5]
remove(List)
Output:-
Enter the string you want: Hello I Am TYBBA(CA) Student
Original String : Hello I Am
TYBBA(CA) Student
No. of Upper case characters : 11
No. of Lower case Characters : 11
Q3= Write Python GUI program to create a digital clock with Tkinter to
display the time
from tkinter import *
from [Link] import *
from time import strftime
root = Tk()
[Link]('Clock')
def time():
string = strftime('%H:%M:%S %p')
[Link](text = string)
[Link](1000, time)
lbl = Label(root, font = ('calibri', 40, 'bold'),
background = 'Red',
foreground = 'white')
[Link](anchor = 'center')
time()
mainloop()
Q4= Write a Python program to check if a given key already exists in a
dictionary. If key exists replace with another key/value pair.
dict={'monday':1, 'tuesday':2}
print("dictionary is :",dict)
check_key=input("enter the key to check")
check_value=input("enter the value")
if check_key in dict:
print(check_key,"is present")
[Link](check_key)
dict[check_key]=check_value
print(dict)
else:
print("check_key is not found")
Output:
Enter key to check:A
Enter Value: 4
Key is present and value of the
key is:
1
Updated dictionary: {'B': 2, 'C':
3, 'A': '4'}
Q5= Write a python script to define a class student having members roll no,
name, age, gender. Create a subclass called Test with member marks of 3
subjects. Create three objects of the Test class and display all the details of
the student with total marks.
class student:
def accept(self):
[Link]=int(input("enter the student rollno:"))
[Link]=(input("enter the student name:"))
[Link]=int(input("enter the student age:"))
[Link]=(input("enter the student gender:"))
def display(self):
print("student rollno:",[Link])
print("student name:",[Link])
print("student age:",[Link])
print("student gender:",[Link])
class test(student):
def getdata(self):
self.m1=int(input("enter marks of m1 subject:"))
self.m2=int(input("enter marks of m2 subject:"))
self.m3=int(input("enter marks of m3 subject:"))
def putdata(self):
print("m1 marks:",self.m1)
print("m2 marks:",self.m2)
print("m3 marks:",self.m3)
print("total marks:",self.m1+self.m2+self.m3)
n=int(input("enter how many student:"))
s=[]
for i in range(0,n):
x=input("enetr the object name:")
[Link](x)
print(s)
for j in range(0,n):
s[j]=test()
s[j].accept()
s[j].display()
print("display details of student:")
s[j].getdata()
s[j].putdata()
Output=
Enter How may students2
Enter Object Name:A
['A']
Enter Object Name:B
['A', 'B']
Enter Student Roll No:101
Enter Student Name:Priti
Enter Student Age:10
Enter Student Gender:F
Enter Marks of Marathi Subject10
Enter Marks of Hindi Subject20
Enter Marks of Eglish Subject30
Display Details of Student 1
Student Roll No: 101
Student Name: Priti
Student Age: 10
Student Gender: F
Marathi Marks: 10
Hindi Marks: 20
English Marks: 30
Total Marks: 60
Enter Student Roll No:201
Enter Student Name:Suhas
Enter Student Age:20
Enter Student Gender:M
Enter Marks of Marathi Subject30
Enter Marks of Hindi Subject40
Enter Marks of Eglish Subject50
Display Details of Student 2
Student Roll No: 201
Student Name: Suhas
Student Age: 20
Student Gender: M
Marathi Marks: 30
Hindi Marks: 40
English Marks: 50
Total Marks: 120
Q6= Write Python GUI program to create background with changing colors
from tkinter import*
root=Tk()
[Link]("500x500")
def change_color():
[Link](background="Red")
button=(root,text == "Red colour :
,command=="change_color1").pack(pady=10)
def change_color1():
[Link](background="Blue")
button=(root,text == "Blue colour
,command=="change_color1").pack(pady=10)
[Link]
Q7= Define a class Employee having members id, name, department, salary.
Create a subclass called manager with member bonus. Define methods
accept and display in both the classes. Create n objects of the manager class
and display the details of the manager having the maximum total salary
(salary+bonus).
class Employee:
def __init__(self, id=0, name="", department="", salary=0.0):
[Link] = id
[Link] = name
[Link] = department
[Link] = salary
def accept(self):
[Link] = int(input("Enter Employee ID: "))
[Link] = input("Enter Employee Name: ")
[Link] = input("Enter Department: ")
[Link] = float(input("Enter Salary: "))
def display(self):
print(f"ID: {[Link]}")
print(f"Name: {[Link]}")
print(f"Department: {[Link]}")
print(f"Salary: ${[Link]:.2f}")
class Manager(Employee):
def __init__(self, id=0, name="", department="", salary=0.0, bonus=0.0):
super().__init__(id, name, department, salary)
[Link] = bonus
def accept(self):
super().accept()
[Link] = float(input("Enter Bonus: "))
def display(self):
super().display()
print(f"Bonus: ${[Link]:.2f}")
def total_salary(self):
return [Link] + [Link]
def main():
n = int(input("Enter number of managers: "))
managers = []
for i in range(n):
print(f"\nEntering details for manager {i + 1}:")
manager = Manager()
[Link]()
[Link](manager)
if managers:
max_manager = max(managers, key=lambda m: m.total_salary())
print("\nManager with the highest total salary:")
max_manager.display()
print(f"Total Salary: ${max_manager.total_salary():.2f}")
else:
print("No managers to display.")
if __name__ == "__main__":
main()
Output=
Enter number of managers: 1
Entering details for manager 1:
Enter Employee ID: 101
Enter Employee Name: Saniya
Enter Department: Testing
Enter Salary: 25000
Enter Bonus: 5000
Manager with the highest total salary:
ID: 101
Name: Saniya
Department: Testing
Salary: $25000.00
Bonus: $5000.00
Total Salary: $30000.00
Q8= Write a Python script using class, which has two methods get_String and
print_String. get_String accept a string from the user and print_String print
the string in upper case.
class string1:
def get_string(self):
self.s=input("enter the string")
def print_string(self):
str=self.s
print("string in uppercase:",[Link]())
s1=string1()
s1.get_string()
s1.print_string()
Output:
Hello i am TYBBA(CA) Student
HELLO I AM TYBBA(CA) STUDEN
Q9= Write a python script to find the repeated items of a tuple
tup=(2,4,5,4,5,6)
print(tup)
count=[Link](6)
print(count)
Output=
(2, 4, 5, 4, 5, 6)
1
Q10= Write a Python class which has two methods get_String and
print_String. get_String accept a string from the user and print_String print
the string in upper case. Further modify the program to reverse a string
word by word and print it in lower case.
class myfunction:
def get(self):
[Link]=input("enter the string:")
def display(self):
s=[Link]
print("upper case:",[Link]())
cnt=len(s)
i=cnt-1
revstr=""
while(i>=0):
revstr=revstr + s[i]
i=i-1
print("reverse and lower case:",[Link]())
m=myfunction()
[Link]()
[Link]()
Output:
Enter any String: saniya
String in Upper Case: SANIYA
String in Reverse & Lower case: ayinas
Q11= Write a Python script using class to reverse a string word by word
class string:
def get_string(self):
self.s=input("enter the string:")
def print_string(self):
str=self.s
print("print string:",str)
cnt=len(str)
i=cnt-1
revstr=""
while(i>=0):
revstr=revstr + str[i]
i=i-1
print("reverse string is:",revstr)
c=string()
c.get_string()
c.print_string()
Output:
Enter any String: Hello
String in Reverse: olleH
Q12= Write Python GUI program to display an alert message when a button
is pressed.
import tkinter as tk
from [Link] import *
top = [Link]()
[Link]("300x200")
def onClick():
[Link]("Alter Message","I am studying in TY BBA(CA)
class")
button = [Link](top,text="Click me",command=onClick)
[Link]()
[Link]()
Output:
Q13=Write a Python program to compute element-wise sum of given tuples.
Original lists: (1, 2, 3, 4) (3, 5, 2, 1) (2, 2, 3, 1) Element-wise sum of the said
tuples: (6, 9, 8, 6)
x = (1,2,3,4);y = (3,5,2,1);z = (2,2,3,1)
print("Original lists:")
print(x)
print(y)
print(z)
print("\nElement-wise sum of the said tuples:")
result = tuple(map(sum, zip(x, y, z)))
print(result)
Output=
Original lists:
(1, 2, 3, 4)
(3, 5, 2, 1)
(2, 2, 3, 1)
Element-wise sum of the said tuples:
(6, 9, 8, 6)
Q14= Write Python GUI program to add menu bar with name of colors as
options to change the background color as per selection from menu option.
from tkinter import *
app = Tk()
[Link]("Menu Color Change")
[Link]("300x300")
menubar = Menu(app, background='blue', fg='white')
file = Menu(menubar, tearoff=False, background='yellow')
edit = Menu(menubar, tearoff=False, background='pink')
file.add_command(label="New")
file.add_command(label="Exit", command=[Link])
edit.add_command(label="Cut")
edit.add_command(label="Copy")
edit.add_command(label="Paste")
menubar.add_cascade(label="File", menu=file)
menubar.add_cascade(label="Edit", menu=edit)
[Link](menu=menubar)
[Link]()
Q15= Write a Python GUI program to create a label and change the label
font style (font name, bold, size) using tkinter module.
import tkinter as tk
root = [Link]()
[Link]("Welcome to student")
my_label = [Link](root,text="hello welcome all of you", font= ("times new
roman",10))
my_label.grid(column=0,row=0)
[Link]()
Q16=: Write a python program to count repeated characters in a string.
Sample string: 'thequickbrownfoxjumpsoverthelazydog' Expected output: o-
4, e-3, u-2, h-2, r-2, t-2
str="thequickbraconfoxjumpsovertlongday"
dict={}
for ch in str:
if ch in dict:
dict[ch]=dict[ch]+1
else:
dict[ch] = 1
for key in dict:
print(key,"_",dict[key])
Output:
Enter the string you want: Hello I Am TYBBA(CA) Student
4
A3
e2
l
2
B
2
t2
Q17=Write a program to implement
the concept of queue using list
q=[2,4,6]
def insert():
if len(q)==size:
print("queue is full:")
else:
element=input("enter the
number:")
[Link](element)
print(element,"is added")
def delete():
if len(q)==0:
print("queue is empty")
else:
e=[Link](0)
print("element removed:")
def display():
print(q)
size=int(input("enter the size of
queue:"))
print("select the option:[Link] [Link]
[Link]")
choice=int=(input("enter the choice"))
if choice==1:
insert()
elif choice==2:
delete()
elif choice==3:
display()
else:
print("invalid")
Output:
Enter the size of Queue:2
Select the Operation: [Link] [Link]
[Link] [Link] 1
Enter the
element:10
10 is added
to the
Queue!
Select the Operation: [Link] [Link]
[Link] [Link] 1
Enter the
element:20
20 is added
to the
Queue!
Select the Operation: [Link] [Link]
[Link] [Link]
1
Queue is Full!!!!
Select the Operation: [Link] [Link]
[Link] [Link] 3
['10', '20']
Select the Operation: [Link] [Link]
[Link] [Link]
2
element removed!!: 10
Select the Operation: [Link] [Link]
[Link] [Link] 4
Q18= Write a Python GUI program to accept dimensions of a cylinder and
display the surface area and volume of cylinder.
import tkinter as tk
window=[Link]()
[Link]("300x300")
def volume():
pi=22/7
height=[Link](1.0,"end-1c")
radius=[Link](1.0,"end-1c")
volume=pi*float(radius)*float(radius)*float(height)
[Link](text="volume is :" + str(volume))
def surfacearea():
pi=22/7
height=[Link](1.0,"end-1c")
radius=[Link](1.0,"end-1c")
sur_area=((2*pi*float(radius)*float(radius))+((2*pi*float(radius)*float(height))))
[Link](text="surface area is :"+str(sur_area))
txtheight=[Link](window,height=2,width=20)
txtradius=[Link](window,height=2,width=20)
[Link]()
[Link]()
b1=[Link](window,text="volume",command=volume)
b2=[Link](window,text="surface area",command=surfacearea)
[Link]()
[Link]()
lbl=[Link](window,text="")
[Link]()
[Link]()
Output=
Q19= Write a Python class named
Student with two attributes
student_name, marks. Modify the
attribute values of the said class and
print the original and modified values
of the said attributes
class student:
def accept(self):
[Link]=input("enter the name")
[Link]=input("enter the mark")
def modify(self):
[Link]=[Link]
[Link]=int(input("enter the new
mark"))
print("oldmark:",[Link])
print("student name is :,[Link])
print("student mark is :",[Link])
s1=student()
[Link]()
[Link]()
Output:
Enter Student Name:Geeta
Enter Student Total Marks:67
Enter Student New Total Marks:78
Student Name: Geeta
Old Total Mark: 67
New Total Mark: 78
Q20= Write a python program to accept string and remove the characters
which have odd index values of given string using user defined function
def myfunction():
str=input("enter the string")
cnt=len(str)
newstring=""
for i in range(0,cnt):
if i%2==0:
newstr=newstr=str[i]
print("new string with removed index is :",newstring)
myfunction()
Output:
Enter the string you want:
Hello
Hlo
Q21=Write a python script to create a class Rectangle with data member’s
length, width and methods area, perimeter which can compute the area and
perimeter of rectangle
class rect :
def __init__(self,length,width):
[Link]=length
[Link]=width
def rectarea(self):
[Link]=[Link]*[Link]
print("area of rectangle is :",[Link])
def rectperi(self):
[Link]=2*([Link]+[Link])
print("perimeter of rectangle is :",[Link])
length=int(input("enter length:"))
width=int(input("enter width:"))
b=rect(length,width)
[Link]()
[Link]()
Output:
Enter Length:2
Enter Width:3
Area of Rectangle: 6
Perimeter of Rectangle: 10
Q22= Write Python GUI program that takes input string and change letter
to upper case when a button is pressed.
import tkinter as tk
window= [Link]()
[Link]("case changer")
[Link]("200x100")
def upper_case():
result=[Link]()
[Link](text=[Link]())
entry=[Link](window)
[Link]()
b1=[Link](window,text="upper
case",command="upper_case")
[Link]()
lbl=[Link](window,text="")
[Link]()
[Link]()
Output =
Q23= Create a list a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] and write a python
program that prints out all the elements of the list that are less than 5
List=[1,1,2,3,5,8,13,21,34,55,89]
cnt = len(List)
for i in range(0,cnt):
if(List[i]<10):
print(List[i])
Output:
[1, 1, 2, 3]
Q24= Write a python script to define the class person having members name,
address. Create a subclass called Employee with members staffed salary.
Create 'n' objects of the Employee class and display all the details of the
employee.
class person:
def accept(self):
[Link]=input("Enter the Name
of person")
[Link]=input("Enter the
Address of person")
def display(self):
print("person Name:",[Link])
print("person
Address:",[Link])
class Employee(person):
def get(self):
[Link]=int(input("Enter Salary of
Employee"))
def put(self):
print("Salary of
Employee",[Link])
n=int(input("Enter how many
Employee"))
lst=[]
for i in range(0,n):
obj=input("Enter object Name")
[Link](obj)
print(lst)
for j in range(0,n):
lst[j]=Employee()
lst[j].accept()
lst[j].get()
print("/n Dispaly details of
Employee",j+1)
lst[j].display()
lst[j].put()
Output:
Enter How may Employee: 1
Enter Object Name:A
['A']
Enter tne name of Person: Saniya
Enter Address of Person: Pune
Enter Salary of Employee1234
Display Details of Employee 1
Person Name: Saniya
Student Address: Pune
Salary of Employee: 1234
Q25=: Write a Python GUI program to accept a number form user and
display its multiplication table on button click.
from tkinter import *
window=Tk()
[Link]("multiplication Table")
def multiply():
n=int([Link]())
str1="table of"+str(n) + "\n------------
----\n"
for x in range(1,11):
str1 = str1 + " " + str (n) + "x" +
str(x) + "=" + str(n*x) + "\n"
output_lbl.config(text=str1,justify=LEF
T)
lbl=Label(text ="enter a
number",font=('Arial',12))
output_lbl=Label(font=('Arial',12))
entry=Entry(font=('Arial',12),width=5)
btn=Button(text="Click to
multiply",font=('Arial',12),command=m
ultiply)
[Link](row=0,column=0,padx=10,pady
=10)
[Link](row=0,column=1,padx=10,pa
dy=10,ipady=10)
[Link](row=0,column=2,padx=10,pad
y=10)
output_lbl.grid(row=1,column=0,colum
nspan=3,padx=10,pady=10)
[Link]()
Output=
Q26= Define a class named Shape and its subclass(Square/ Circle). The
subclass has an init function which takes an argument (Lenght/redious).
Both classes should have methods to calculate area and volume of a given
shape.
class Shape:
pass
class Square(Shape):
def __init__(self,l2):
self.l=12
def SArea(self):
a=self.l * self.l
print("Area of Square:",a)
def Svolume(self):
v=3 * self.l
print("volumn of Square:",p)
class Circle(Shape):
def __init__(self,r2):
self.r=r2
def CArea(self):
a=3.14 * self.r * self.r
print("Area of Circle:",a)
def SPerimeter(self):
p=4 * self.l
print("Perimeter of Square:",p)
l1=int(input("Enter Length of Square:"))
obj=Square(l1)
[Link]()
[Link]()
r1=int(input("Enter Radius of Circle:"))
obj=Circle(r1)
[Link]()
[Link]()
Output:
Enter Length of Square: 2
Area of Square: 4
Perimeter of Square: 8
Enter Radius of Circle: 3
Area of Circle: 28.259999999999998
Circumference of Circle: 18.84
Q27= Write a python program to create a class Circle and Compute the
Area and the circumferences of the circle.(use parameterized constructor)
class Circle():
def __init__(self,Radius):
[Link]=Radius
def area(self):
a=pi*[Link]*[Link]
return round(a,2)
def circumference(self):
c=2*[Link]*pi
return round(c,2)
r= int(input('enter radius of circle : '))
a=Circle(r)
print('Area of circle is : ',[Link]())
print('Circumference of circle is : ',[Link]())
Output=
Enter radius of circle:5
Area of circle is :78.54
Circumference of circle is :31.42
Q28=Write a Python script to generate and print a dictionary which contains
a number (between 1 and n) in the form(x,x*x). Sample Dictionary (n=5)
Expected Output: {1:1, 2:4, 3:9, 4:16, 5:25}
n=int(input("Input a number : "))
d ={}
for x in range(1,n+1):
d[x]=x*x
print(d)
Output=
Input a number : 5
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
Q29= Write a Python Program to Check if given number is prime or not.
Also find factorial of the given no using user defined function.
def prime(num):
flag=0
for i in range(2,num):
if num%i==0:
flag=1
break
if flag == 0:
print("Number is prime:")
else:
print("Number is not prime:")
def fact(num):
f=1
for i in range(1,num+1):
f=f*I
print("Factorial of given no is :",f)
n=int(input("Enter any no to check:"))
prime(n)
fact(n)
Output:
Enter any number to Check:3
Number is Prime
Factorial of Given number is: 6
Q30= Write Python GUI program which accepts a number n to displays each
digit of number in words.
def printvalue(digit):
if(digit == '0'):
print("zero",end="")
if digit =='1':
print("one",end="")
if digit =='2':
print("two",end="")
if digit =='3':
print("three",end="")
if digit =='4':
print("four",end="")
if digit =='5':
print("five",end="")
if digit =='6':
print("six",end="")
if digit =='7':
print("seven",end="")
if digit =='8':
print("eigth",end="")
if digit =='9':
print("nigth",end="")
def printword(N):
i=0
length=len(N)
while i<length:
printvalue(N[i])
i=i+1
N="0123456789"
printword(N)
Output=
Zero one two three four five six seven eigth night
Q31= Write a Python script to Create a Class which Performs Basic
Calculator Operations
class calculation:
def add(self):
self.a = int(input("enter the first no:"))
self.b = int(input("enter the second no:"))
self.c=self.a+self.b
print("addition of no:",self.c)
def sub(self):
self.a = int(input("enter the first no:"))
self.b = int(input("enter the second no:"))
self.c=self.a-self.b
print("substraction of no:",self.c)
def multi(self):
self.a = int(input("enter the first no:"))
self.b = int(input("enter the second no:"))
self.c=self.a*self.b
print("multiplication of no:",self.c)
def div(self):
self.a = int(input("enter the first no:"))
self.b = int(input("enter the second no:"))
self.c=self.a/self.b
print("division of no:",self.c
obj = calculation()
while True:
print("\n1. addition")
print("\n2. substraction")
print("\n3. multiplication")
print("\n4. division")
print("\n5. exit")
ch = int(input("enter your choice:"))
if ch ==1:
[Link]()
elif ch ==2:
[Link]()
elif ch ==3:
[Link]()
elif ch==4:
[Link]()
elif ch==5:
print("\n program stopped")
break
else:
print("you have entered wrong option:”)
Output=
1. addition
2. substraction
3. multiplication
4. division
5. exit
enter your choice:1
enter the first no:5
enter the second no:9
addition of no: 14
Q32= Write a Python program to accept two lists and merge the two lists into
list of tuple.
l1=[1,2,3,5]
l2=["saniya","shaikh"]
t1=tuple(l1)
t2=tuple(l2)
t3=t1 + t2
print(t3)
Output:
Enter number of elements of first list : 3
10
20
30
[10, 20, 30]
Enter number of elements of second list
:3
Q33=: Python Program to Create a Class in which One Method Accepts a
String from the User and Another method Prints it. Define a class named
Country which has a method called print Nationality. Define subclass named
state from Country which has a mehtod called printState. Write a method to
print state, country and nationality.
class country:
def accept(self):
[Link] = input("enter the country name:")
[Link] = input("enter the nationality:")
def print(self):
print([Link])
def print_nationality(self):
print([Link])
class state(country):
def printstate(self):
[Link] = input("enter state:")
print([Link])
obj=state()
[Link]()
[Link]()
[Link]()
obj.print_nationality()
Output:
Enter Country Name: India
Enter State Name: Maharashtra
Country Name is: India
State Name is: Maharashtra
Q34= Write a python script to generate Fibonacci terms using generator
function.
def generator(r):
a=0;b=1
for i in range (1,r):
print(b)
a,b=b,a+b
n=int(input('Enter a number :'))
if n==0:
print('0')
else:
print(0)
generator(n)
Output=
Enter a number :5
0
1
1
2
3
Q35= Write Python GUI program to accept a number n and check whether it
is Prime, Perfect or Armstrong number or not. Specify three radio buttons.
from tkinter import*
def perfect():
number=int([Link]())
count = 0
for i in range(1, number):
if number % i == 0:
count = count + i
if count == number:
[Link]()
print(number, 'The number is a Perfect number!')
else:
[Link]()
print(number, 'The number is not a Perfect number!')
def armstrong():
number=int([Link]())
count = 0
temp = number
while temp > 0:
digit = temp % 10
count += digit ** 3
temp //= 10
if number == count:
[Link]()
print(number, 'is an Armstrong number')
else:
[Link]()
print(number, 'is not an Armstrong number')
def prime():
number=int([Link]())
if number > 1:
for i in range(2,number):
if (number % i) == 0:
[Link]()
print(number,"is not a prime number")
print(i,"times",number//i,"is",number)
break
else:
[Link]()
print(number,"is a prime number")
else:
[Link]()
print(number,"is not a prime number")
root=Tk()
[Link]('Prime, Perfect or Armstrong number')
[Link]('300x200')
numberFeald=Entry(root)
[Link]()
Button1=Button(root,text='Button',command=lambda:[armstrong(),prime(),perfect
()])
[Link]()
prime2=IntVar()
perfect2=IntVar()
armstrong2=IntVar()
armstrong1=Radiobutton(root,text='armstrong',variable=armstrong2,value=1)
prime1=Radiobutton(root,text='prime',variable=prime2,value=1)
perfect1=Radiobutton(root,text='perfect',variable=perfect2,value=1)
[Link]()
[Link]()
[Link]()
[Link]()