SlideShare a Scribd company logo
1 of 16
Download to read offline
1
1) Read a path from user and display all directories and files on that path
along with their properties. (Python)
# import OS module
import os
# Get the list of all files and directories
path = "C:UsersIMRDDesktopABC"
dir_list = os.listdir(path)
print("Files and directories in '", path, "' :")
# prints all files
print(dir_list)
2) Write a program to demonstrate class, object, Inheritance. (Python)
class Animal:
def speak(self):
print("Animal Speaking")
#child class Dog inherits the base class Animal
class Dog(Animal):
def bark(self):
print("dog barking")
d = Dog()
d.bark()
d.speak()
2
3) Write a program to demonstrate Module and Package. (Python)
File 1) mymodule.py
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
File 2) File2.py
import mymodule #mymodule is the first file name
a = mymodule.person1["age"]
print(a)
Note: Run File2.py (save File 1 as a name mymodule.py and this name use as
a package in File 2)
4) Write a function to print prime number in the given range n1 to n2(Python)
lower=1
upper=10
print("Prime no.between",lower,"änd",upper,"are:")
for num in range(lower,upper+1):
if num>1:
for i in range(2,num):
if(num%i)==0:
break
else:
print(num)
3
5) Write a program to find sum of array.(Python)
def _sum(arr):
sum = 0
for i in arr:
sum = sum + i
return(sum)
# main function
if __name__ == "__main__":
# input values to list
arr = [12, 3, 4, 15]
n = len(arr)
ans = _sum(arr)
print('Sum of the array is ', ans)
Output: Sum of the array is 34
6) Demonstrate exception handling with minimum 3 types of
exception.(python)
i) Write.py
file=open("111.txt","w")
file.write("hey this is my file")
file.close()
ii) Read.py
file=open("111.txt","r")
someText=file.read()
print(someText)
file.close()
4
iii) Append.py
file =open("111.txt" ,"a")
file.write("n new line ")
file.close()
7) Write and demonstrate program to read an integer and functions to check
given number is Armstrong or not. (Python).
num=int(input("Enter a number:"))
sum=0
temp=num
while temp>0:
digit=temp % 10
sum += digit ** 3
temp //= 10
if num==sum:
print(num,"is an armstrong number")
else:
print(num,"is not an armstrong number")
8) Write the program to read and multiply two matrices of given size. (Python)
# take a 2x2 matrix
A = [[2,2],
[1,1]]
# take a 2x2 matrix
B = [[7,1],
[11,2]]
5
result = [[0, 0],
[0, 0,]]
# iterating by row of A
for i in range(len(A)):
# iterating by column by B
for j in range(len(B[0])):
# iterating by rows of B
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]
for r in result:
print(r)
9) Write the program to demonstrate lambda and filter(Python)
d=lambda p:p*5
t=lambda p:p*2
x=7
x=d(x)
x=t(x)
x=d(x)
print(x)
nums=[6,16,26,36,46,56]
result=list(map(lambda x:x*2+2-4,nums))
print (result)
t=[1,2,3,4,5,6,7,8,9]
result=filter (lambda v:v%2!=0,t)
print (list(result))
6
10) Create a dictionary by adding the key value pair from user. Check for
duplicate before adding. Display the value of key given by user. (Python)
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print (dict['one']) # Prints value for 'one' key
print (dict[2]) # Prints value for 2 key
print (tinydict) # Prints complete dictionary
print (tinydict.keys()) # Prints all the keys
print (tinydict.values())
11) Demonstrate List and Dictionary with its important function (minimum
4). (Python)
#List
a = ["abc", "pqr", "www"]
print(a)
print(a[1])
#define dictionary's
d={6:"six"}
d[5]="five"
d[10]="ten"
print("dictionary",d)
del d[10]
print("dictionary",d)
12) Write a program to read a path string from user and list all directories
and filename separately. (Python).
from os import walk
# folder path
7
dir_path = r'Desktop'
# list to store files name
res = []
for (dir_path, dir_names, file_names) in walk(dir_path):
res.extend(file_names)
print(res)
13) Program to demonstrate function from path module. (Python)
# Python program to explain os.path.normpath() method
# importing os.path module
import os.path
# Path
path = 'Desktop'
# Normalize the specified path
# using os.path.normpath() method
norm_path = os.path.normpath(path)
# Print the normalized path
print(norm_path)
14) Program to demonstrate function from path module. (Python)
i) Join ii)Split
def split_string(string):
# Split the string based on space delimiter
list_string = string.split(' ')
8
return list_string
def join_string(list_string):
# Join the string based on '-' delimiter
string = '-'.join(list_string)
return string
# Driver Function
if __name__ == '__main__':
string = 'hey this is my file'
# Splitting a string
list_string = split_string(string)
print(list_string)
# Join list of strings into one
new_string = join_string(list_string)
print(new_string)
iii) normpath() Method
import os.path
path = r'C:/Users'
norm_path = os.path.normpath(path)
print(norm_path)
path = r'C:Users.Documents'
norm_path = os.path.normpath(path)
print(norm_path)
9
path = r'C:Usersadmintemp..Documents'
norm_path = os.path.normpath(path)
print(norm_path)
Output: C:Users
C:UsersDocuments
C:UsersadminDocuments
iv) exit() Method
# Python program to demonstrate
# exit()
for i in range(10):
if i == 5:
print(exit)
exit()
print(i)
Output:
0
1
2
3
4
10
15) Python Program for GUI Architecture-
i)Python Tkinter Widgets – Button
from tkinter import *
from tkinter import messagebox
top = Tk()
top.geometry("100x100")
def helloCallBack():
msg=messagebox.showinfo( "Hello Python", "Hello World")
B = Button(top, text ="Hello", command = helloCallBack)
B.place(x=50,y=50)
top.mainloop()
ii) Python Tkinter Widgets - Checkbutton:
>>> from tkinter import *
>>> top=Tk()
>>> CheckVar1=IntVar()
>>> CheckVar2=IntVar()
>>> C1=Checkbutton
>>>C1=Checkbutton(top,text="Pizza",variable=CheckVar1,onvalue=1,offvalue=0,h
eight=5,width=20)
>>>C2=Checkbutton(top,text="Fries",variable=CheckVar2,onvalue=1,offvalue=0,h
eight=5,width=20)
>>> C1.pack()
11
>>> C2.pack()
>>> top.mainloop()
iii) Python Tkinter Widgets - Canvas :
>>> from tkinter import *
>>> from tkinter import messagebox
>>> top=Tk()
>>> C=Canvas(top,bg="cyan",height=100,width=100)
>>> coord=10,50,90,70
>>> arc=C.create_arc(coord,start=0,extent=97,fill='black')
>>> line=C.create_line(10,10,50,70,fill='white')
>>> C.pack()
>>> top.mainloop()
iv) Python Tkinter Widgets - Entry:
>>> from tkinter import *
>>> top=Tk()
>>> L1=Label(top,text="Enrolment Number")
>>> L1.pack(side=LEFT)
>>> E1=Entry(top,bd=3)
>>> E1.pack(side=RIGHT)
>>> top.mainloop()
12
v) Python Tkinter Widgets - Frame:
>>> from tkinter import *
>>> top=Tk()
>>> frame=Frame(top)
>>> frame.pack()
>>> frametwo=Frame(top)
>>> frametwo.pack(side=BOTTOM)
>>> redbutton=Button(frame,text="One",fg="red")
>>> redbutton.pack(side=LEFT)
>>> bluebutton=Button(frame,text="Two",fg="blue")
>>> bluebutton.pack(side=LEFT)
>>> greenbutton=Button(frametwo,text="Three",fg="green")
>>> greenbutton.pack(side=BOTTOM)
>>> top.mainloop()
vi) Python Tkinter Widgets - Listbox:
>>> from tkinter import *
>>> top=Tk()
>>> LB1=Listbox(top)
>>> LB1.insert(1,"Hindi")
>>> LB1.insert(2,"Romanian")
>>> LB1.insert(3,"English")
>>> LB1.insert(4,"Gujarati")
13
>>> LB1.pack()
>>> top.mainloop()
vii) Python Tkinter Widgets – Menu Button:
>>> from tkinter import *
>>> top=Tk()
>>> mb=Menubutton(top,text="style",relief=RAISED)
>>> mb.grid()
>>> mb.menu=Menu(mb,tearoff=0)
>>> mb["menu"]=mb.menu
>>> balayageVar=IntVar()
>>> sombreVar=IntVar()
>>> mb.menu.add_checkbutton(label='Balayage',variable=balayageVar)
>>> mb.menu.add_checkbutton(label='Sombre',variable=sombreVar)
>>> mb.pack()
>>> top.mainloop()
viii) Python Tkinter Widgets – Radiobutton:
>>> from tkinter import *
>>> def sel():
selection=f"Enjoy your {var.get()}"
label.config(text=selection)
>>> top=Tk()
14
>>> var=StringVar()
>>> R1=Radiobutton(top,text="pizza
slice",variable=var,value='pizza',command=sel
>>> R1.pack(anchor=W)
>>> R2=Radiobutton(top,text="burger",variable=var,value='burger',command=sel)
>>> R2.pack(anchor=W)
>>> R3=Radiobutton(top,text="fries",variable=var,value='fries',command=sel)
>>> R3.pack(anchor=W)
>>> label=Label(top)
>>> label.pack()
>>> top.mainloop()
iX) Python Tkinter Widgets – Scrollbar:
>>> from tkinter import *
>>> top=Tk()
>>> scrollbar=Scrollbar(top)
>>> scrollbar.pack(side=RIGHT,fill=X)
>>> scrollbar.pack(side=RIGHT,fill=Y)
>>> list=Listbox(top,yscrollcommand=scrollbar.set)
>>> for line in range(22):
list.insert(END,f"Line {str(line)}")
>>> list.pack(side=LEFT,fill=BOTH)
>>> scrollbar.config(command=list.yview)
15
>>> top.mainloop()
16)Write a function to replace smiley characters in a given sentence with Emoji
/ word sentiment using Dictionary. (Python)
# grinning face
print("U0001f600")
# grinning squinting face
print("U0001F606")
# rolling on the floor laughing
print("U0001F923")
#Crying face
print("N{crying face}")
# grinning face
print("N{grinning face}")
# slightly smiling face
print("N{slightly smiling face}")
# winking face
print("N{winking face}")
17) Create a sample log file and demonstrate Rotating of files
import logging
import time
from logging.handlers import RotatingFileHandler
16
---------------------------------------------------------------------
def create_rotating_log(path):
"""
Creates a rotating log
"""
logger = logging.getLogger("Rotating Log")
logger.setLevel(logging.INFO)
# add a rotating handler
handler = RotatingFileHandler(path, maxBytes=20,
backupCount=5)
logger.addHandler(handler)
for i in range(10):
logger.info("This is test log line %s" % i)
time.sleep(1.5)
----------------------------------------------------------------------
if __name__ == "__main__":
log_file = "test.log"
create_rotating_log(log_file)
NOTE-[Before executing this program make sure firstly you create folder and save
this program in a folder because log files is also create at same location.]

More Related Content

Similar to 8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your basics in designing.

Python basic
Python basic Python basic
Python basic sewoo lee
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in cgkgaur1987
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212Mahmoud Samir Fayed
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxHongAnhNguyn285885
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUadAccount
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In RRsquared Academy
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfparthp5150s
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingMuthu Vinayagam
 
PYTHON PROGRAMMING for first year cse students
PYTHON  PROGRAMMING for first year cse studentsPYTHON  PROGRAMMING for first year cse students
PYTHON PROGRAMMING for first year cse studentsthiyagarajang21
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust languageGines Espada
 
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196Mahmoud Samir Fayed
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7decoupled
 

Similar to 8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your basics in designing. (20)

Python basic
Python basic Python basic
Python basic
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Mouse programming in c
Mouse programming in cMouse programming in c
Mouse programming in c
 
The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212The Ring programming language version 1.10 book - Part 35 of 212
The Ring programming language version 1.10 book - Part 35 of 212
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
Unit2 input output
Unit2 input outputUnit2 input output
Unit2 input output
 
beginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptxbeginners_python_cheat_sheet_pcc_all (3).pptx
beginners_python_cheat_sheet_pcc_all (3).pptx
 
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptxUsing-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdfsolution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
solution-of-practicals-class-xii-comp.-sci.-083-2021-22 (1).pdf
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
PYTHON PROGRAMMING for first year cse students
PYTHON  PROGRAMMING for first year cse studentsPYTHON  PROGRAMMING for first year cse students
PYTHON PROGRAMMING for first year cse students
 
Short intro to the Rust language
Short intro to the Rust languageShort intro to the Rust language
Short intro to the Rust language
 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
 
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 
Python course Day 1
Python course Day 1Python course Day 1
Python course Day 1
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 

More from Yashpatel821746

newpython.pdfnewpython.pdfnewpython.pdf.
newpython.pdfnewpython.pdfnewpython.pdf.newpython.pdfnewpython.pdfnewpython.pdf.
newpython.pdfnewpython.pdfnewpython.pdf.Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...Yashpatel821746
 

More from Yashpatel821746 (6)

newpython.pdfnewpython.pdfnewpython.pdf.
newpython.pdfnewpython.pdfnewpython.pdf.newpython.pdfnewpython.pdfnewpython.pdf.
newpython.pdfnewpython.pdfnewpython.pdf.
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
 
UDP.yash
UDP.yashUDP.yash
UDP.yash
 
7720
77207720
7720
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 

Recently uploaded

Khanpur Call Girls : ☎ 8527673949, Low rate Call Girls
Khanpur Call Girls : ☎ 8527673949, Low rate Call GirlsKhanpur Call Girls : ☎ 8527673949, Low rate Call Girls
Khanpur Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?kexey39068
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiMalviyaNagarCallGirl
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Parkjosebenzaquen
 
Call Girls in Islamabad | 03274100048 | Call Girl Service
Call Girls in Islamabad | 03274100048 | Call Girl ServiceCall Girls in Islamabad | 03274100048 | Call Girl Service
Call Girls in Islamabad | 03274100048 | Call Girl ServiceAyesha Khan
 
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call Girls
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call GirlsKarol Bagh Call Girls : ☎ 8527673949, Low rate Call Girls
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | Delhi
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | DelhiFULL ENJOY - 9953040155 Call Girls in Karol Bagh | Delhi
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | DelhiMalviyaNagarCallGirl
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfZagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfStripovizijacom
 
MinSheng Gaofeng Estate commercial storyboard
MinSheng Gaofeng Estate commercial storyboardMinSheng Gaofeng Estate commercial storyboard
MinSheng Gaofeng Estate commercial storyboardjessica288382
 
Govindpuri Call Girls : ☎ 8527673949, Low rate Call Girls
Govindpuri Call Girls : ☎ 8527673949, Low rate Call GirlsGovindpuri Call Girls : ☎ 8527673949, Low rate Call Girls
Govindpuri Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call GirlsPragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiFULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiMalviyaNagarCallGirl
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girlsashishs7044
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubaidajasot375
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857delhimodel235
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineShivna Prakashan
 

Recently uploaded (20)

Khanpur Call Girls : ☎ 8527673949, Low rate Call Girls
Khanpur Call Girls : ☎ 8527673949, Low rate Call GirlsKhanpur Call Girls : ☎ 8527673949, Low rate Call Girls
Khanpur Call Girls : ☎ 8527673949, Low rate Call Girls
 
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?
How Can You Get Dubai Call Girls +971564860409 Call Girls Dubai?
 
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call GirlsLaxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
Laxmi Nagar Call Girls : ☎ 8527673949, Low rate Call Girls
 
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | DelhiFULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
FULL ENJOY - 9953040155 Call Girls in Paschim Vihar | Delhi
 
Retail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College ParkRetail Store Scavanger Hunt - Foundation College Park
Retail Store Scavanger Hunt - Foundation College Park
 
Call Girls in Islamabad | 03274100048 | Call Girl Service
Call Girls in Islamabad | 03274100048 | Call Girl ServiceCall Girls in Islamabad | 03274100048 | Call Girl Service
Call Girls in Islamabad | 03274100048 | Call Girl Service
 
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call Girls
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call GirlsKarol Bagh Call Girls : ☎ 8527673949, Low rate Call Girls
Karol Bagh Call Girls : ☎ 8527673949, Low rate Call Girls
 
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | Delhi
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | DelhiFULL ENJOY - 9953040155 Call Girls in Karol Bagh | Delhi
FULL ENJOY - 9953040155 Call Girls in Karol Bagh | Delhi
 
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call GirlsBurari Call Girls : ☎ 8527673949, Low rate Call Girls
Burari Call Girls : ☎ 8527673949, Low rate Call Girls
 
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdfZagor VČ OP 055 - Oluja nad Haitijem.pdf
Zagor VČ OP 055 - Oluja nad Haitijem.pdf
 
MinSheng Gaofeng Estate commercial storyboard
MinSheng Gaofeng Estate commercial storyboardMinSheng Gaofeng Estate commercial storyboard
MinSheng Gaofeng Estate commercial storyboard
 
Govindpuri Call Girls : ☎ 8527673949, Low rate Call Girls
Govindpuri Call Girls : ☎ 8527673949, Low rate Call GirlsGovindpuri Call Girls : ☎ 8527673949, Low rate Call Girls
Govindpuri Call Girls : ☎ 8527673949, Low rate Call Girls
 
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call GirlsPragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
Pragati Maidan Call Girls : ☎ 8527673949, Low rate Call Girls
 
Call~Girl in Rajendra Nagar New Delhi 8448380779 Full Enjoy Escort Service
Call~Girl in Rajendra Nagar New Delhi 8448380779 Full Enjoy Escort ServiceCall~Girl in Rajendra Nagar New Delhi 8448380779 Full Enjoy Escort Service
Call~Girl in Rajendra Nagar New Delhi 8448380779 Full Enjoy Escort Service
 
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | DelhiFULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
FULL ENJOY - 9953040155 Call Girls in Dwarka Mor | Delhi
 
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call GirlsKishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
Kishangarh Call Girls : ☎ 8527673949, Low rate Call Girls
 
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
Dxb Call Girls # +971529501107 # Call Girls In Dxb Dubai || (UAE)
 
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur DubaiBur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
Bur Dubai Call Girls O58993O4O2 Call Girls in Bur Dubai
 
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
Low Rate Call Girls in Laxmi Nagar Delhi Call 9990771857
 
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 MagazineSHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
SHIVNA SAHITYIKI APRIL JUNE 2024 Magazine
 

8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your basics in designing.

  • 1. 1 1) Read a path from user and display all directories and files on that path along with their properties. (Python) # import OS module import os # Get the list of all files and directories path = "C:UsersIMRDDesktopABC" dir_list = os.listdir(path) print("Files and directories in '", path, "' :") # prints all files print(dir_list) 2) Write a program to demonstrate class, object, Inheritance. (Python) class Animal: def speak(self): print("Animal Speaking") #child class Dog inherits the base class Animal class Dog(Animal): def bark(self): print("dog barking") d = Dog() d.bark() d.speak()
  • 2. 2 3) Write a program to demonstrate Module and Package. (Python) File 1) mymodule.py person1 = { "name": "John", "age": 36, "country": "Norway" } File 2) File2.py import mymodule #mymodule is the first file name a = mymodule.person1["age"] print(a) Note: Run File2.py (save File 1 as a name mymodule.py and this name use as a package in File 2) 4) Write a function to print prime number in the given range n1 to n2(Python) lower=1 upper=10 print("Prime no.between",lower,"änd",upper,"are:") for num in range(lower,upper+1): if num>1: for i in range(2,num): if(num%i)==0: break else: print(num)
  • 3. 3 5) Write a program to find sum of array.(Python) def _sum(arr): sum = 0 for i in arr: sum = sum + i return(sum) # main function if __name__ == "__main__": # input values to list arr = [12, 3, 4, 15] n = len(arr) ans = _sum(arr) print('Sum of the array is ', ans) Output: Sum of the array is 34 6) Demonstrate exception handling with minimum 3 types of exception.(python) i) Write.py file=open("111.txt","w") file.write("hey this is my file") file.close() ii) Read.py file=open("111.txt","r") someText=file.read() print(someText) file.close()
  • 4. 4 iii) Append.py file =open("111.txt" ,"a") file.write("n new line ") file.close() 7) Write and demonstrate program to read an integer and functions to check given number is Armstrong or not. (Python). num=int(input("Enter a number:")) sum=0 temp=num while temp>0: digit=temp % 10 sum += digit ** 3 temp //= 10 if num==sum: print(num,"is an armstrong number") else: print(num,"is not an armstrong number") 8) Write the program to read and multiply two matrices of given size. (Python) # take a 2x2 matrix A = [[2,2], [1,1]] # take a 2x2 matrix B = [[7,1], [11,2]]
  • 5. 5 result = [[0, 0], [0, 0,]] # iterating by row of A for i in range(len(A)): # iterating by column by B for j in range(len(B[0])): # iterating by rows of B for k in range(len(B)): result[i][j] += A[i][k] * B[k][j] for r in result: print(r) 9) Write the program to demonstrate lambda and filter(Python) d=lambda p:p*5 t=lambda p:p*2 x=7 x=d(x) x=t(x) x=d(x) print(x) nums=[6,16,26,36,46,56] result=list(map(lambda x:x*2+2-4,nums)) print (result) t=[1,2,3,4,5,6,7,8,9] result=filter (lambda v:v%2!=0,t) print (list(result))
  • 6. 6 10) Create a dictionary by adding the key value pair from user. Check for duplicate before adding. Display the value of key given by user. (Python) dict = {} dict['one'] = "This is one" dict[2] = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'} print (dict['one']) # Prints value for 'one' key print (dict[2]) # Prints value for 2 key print (tinydict) # Prints complete dictionary print (tinydict.keys()) # Prints all the keys print (tinydict.values()) 11) Demonstrate List and Dictionary with its important function (minimum 4). (Python) #List a = ["abc", "pqr", "www"] print(a) print(a[1]) #define dictionary's d={6:"six"} d[5]="five" d[10]="ten" print("dictionary",d) del d[10] print("dictionary",d) 12) Write a program to read a path string from user and list all directories and filename separately. (Python). from os import walk # folder path
  • 7. 7 dir_path = r'Desktop' # list to store files name res = [] for (dir_path, dir_names, file_names) in walk(dir_path): res.extend(file_names) print(res) 13) Program to demonstrate function from path module. (Python) # Python program to explain os.path.normpath() method # importing os.path module import os.path # Path path = 'Desktop' # Normalize the specified path # using os.path.normpath() method norm_path = os.path.normpath(path) # Print the normalized path print(norm_path) 14) Program to demonstrate function from path module. (Python) i) Join ii)Split def split_string(string): # Split the string based on space delimiter list_string = string.split(' ')
  • 8. 8 return list_string def join_string(list_string): # Join the string based on '-' delimiter string = '-'.join(list_string) return string # Driver Function if __name__ == '__main__': string = 'hey this is my file' # Splitting a string list_string = split_string(string) print(list_string) # Join list of strings into one new_string = join_string(list_string) print(new_string) iii) normpath() Method import os.path path = r'C:/Users' norm_path = os.path.normpath(path) print(norm_path) path = r'C:Users.Documents' norm_path = os.path.normpath(path) print(norm_path)
  • 9. 9 path = r'C:Usersadmintemp..Documents' norm_path = os.path.normpath(path) print(norm_path) Output: C:Users C:UsersDocuments C:UsersadminDocuments iv) exit() Method # Python program to demonstrate # exit() for i in range(10): if i == 5: print(exit) exit() print(i) Output: 0 1 2 3 4
  • 10. 10 15) Python Program for GUI Architecture- i)Python Tkinter Widgets – Button from tkinter import * from tkinter import messagebox top = Tk() top.geometry("100x100") def helloCallBack(): msg=messagebox.showinfo( "Hello Python", "Hello World") B = Button(top, text ="Hello", command = helloCallBack) B.place(x=50,y=50) top.mainloop() ii) Python Tkinter Widgets - Checkbutton: >>> from tkinter import * >>> top=Tk() >>> CheckVar1=IntVar() >>> CheckVar2=IntVar() >>> C1=Checkbutton >>>C1=Checkbutton(top,text="Pizza",variable=CheckVar1,onvalue=1,offvalue=0,h eight=5,width=20) >>>C2=Checkbutton(top,text="Fries",variable=CheckVar2,onvalue=1,offvalue=0,h eight=5,width=20) >>> C1.pack()
  • 11. 11 >>> C2.pack() >>> top.mainloop() iii) Python Tkinter Widgets - Canvas : >>> from tkinter import * >>> from tkinter import messagebox >>> top=Tk() >>> C=Canvas(top,bg="cyan",height=100,width=100) >>> coord=10,50,90,70 >>> arc=C.create_arc(coord,start=0,extent=97,fill='black') >>> line=C.create_line(10,10,50,70,fill='white') >>> C.pack() >>> top.mainloop() iv) Python Tkinter Widgets - Entry: >>> from tkinter import * >>> top=Tk() >>> L1=Label(top,text="Enrolment Number") >>> L1.pack(side=LEFT) >>> E1=Entry(top,bd=3) >>> E1.pack(side=RIGHT) >>> top.mainloop()
  • 12. 12 v) Python Tkinter Widgets - Frame: >>> from tkinter import * >>> top=Tk() >>> frame=Frame(top) >>> frame.pack() >>> frametwo=Frame(top) >>> frametwo.pack(side=BOTTOM) >>> redbutton=Button(frame,text="One",fg="red") >>> redbutton.pack(side=LEFT) >>> bluebutton=Button(frame,text="Two",fg="blue") >>> bluebutton.pack(side=LEFT) >>> greenbutton=Button(frametwo,text="Three",fg="green") >>> greenbutton.pack(side=BOTTOM) >>> top.mainloop() vi) Python Tkinter Widgets - Listbox: >>> from tkinter import * >>> top=Tk() >>> LB1=Listbox(top) >>> LB1.insert(1,"Hindi") >>> LB1.insert(2,"Romanian") >>> LB1.insert(3,"English") >>> LB1.insert(4,"Gujarati")
  • 13. 13 >>> LB1.pack() >>> top.mainloop() vii) Python Tkinter Widgets – Menu Button: >>> from tkinter import * >>> top=Tk() >>> mb=Menubutton(top,text="style",relief=RAISED) >>> mb.grid() >>> mb.menu=Menu(mb,tearoff=0) >>> mb["menu"]=mb.menu >>> balayageVar=IntVar() >>> sombreVar=IntVar() >>> mb.menu.add_checkbutton(label='Balayage',variable=balayageVar) >>> mb.menu.add_checkbutton(label='Sombre',variable=sombreVar) >>> mb.pack() >>> top.mainloop() viii) Python Tkinter Widgets – Radiobutton: >>> from tkinter import * >>> def sel(): selection=f"Enjoy your {var.get()}" label.config(text=selection) >>> top=Tk()
  • 14. 14 >>> var=StringVar() >>> R1=Radiobutton(top,text="pizza slice",variable=var,value='pizza',command=sel >>> R1.pack(anchor=W) >>> R2=Radiobutton(top,text="burger",variable=var,value='burger',command=sel) >>> R2.pack(anchor=W) >>> R3=Radiobutton(top,text="fries",variable=var,value='fries',command=sel) >>> R3.pack(anchor=W) >>> label=Label(top) >>> label.pack() >>> top.mainloop() iX) Python Tkinter Widgets – Scrollbar: >>> from tkinter import * >>> top=Tk() >>> scrollbar=Scrollbar(top) >>> scrollbar.pack(side=RIGHT,fill=X) >>> scrollbar.pack(side=RIGHT,fill=Y) >>> list=Listbox(top,yscrollcommand=scrollbar.set) >>> for line in range(22): list.insert(END,f"Line {str(line)}") >>> list.pack(side=LEFT,fill=BOTH) >>> scrollbar.config(command=list.yview)
  • 15. 15 >>> top.mainloop() 16)Write a function to replace smiley characters in a given sentence with Emoji / word sentiment using Dictionary. (Python) # grinning face print("U0001f600") # grinning squinting face print("U0001F606") # rolling on the floor laughing print("U0001F923") #Crying face print("N{crying face}") # grinning face print("N{grinning face}") # slightly smiling face print("N{slightly smiling face}") # winking face print("N{winking face}") 17) Create a sample log file and demonstrate Rotating of files import logging import time from logging.handlers import RotatingFileHandler
  • 16. 16 --------------------------------------------------------------------- def create_rotating_log(path): """ Creates a rotating log """ logger = logging.getLogger("Rotating Log") logger.setLevel(logging.INFO) # add a rotating handler handler = RotatingFileHandler(path, maxBytes=20, backupCount=5) logger.addHandler(handler) for i in range(10): logger.info("This is test log line %s" % i) time.sleep(1.5) ---------------------------------------------------------------------- if __name__ == "__main__": log_file = "test.log" create_rotating_log(log_file) NOTE-[Before executing this program make sure firstly you create folder and save this program in a folder because log files is also create at same location.]