# pip install tkinter
import tkinter as tk
import [Link]
from [Link] import SUNKEN
window = [Link]()
[Link]('Calculator-GeeksForGeeks')
frame = [Link](master=window, bg="skyblue", padx=10)
[Link]()
entry = [Link](master=frame, relief=SUNKEN, borderwidth=3, width=30)
[Link](row=0, column=0, columnspan=3, ipady=2, pady=2)
def myclick(number):
[Link]([Link], number)
def equal():
try:
y = str(eval([Link]()))
[Link](0, [Link])
[Link](0, y)
except:
[Link]("Error", "Syntax Error")
def clear():
[Link](0, [Link])
button_1 = [Link](master=frame, text='1', padx=15,
pady=5, width=3, command=lambda: myclick(1))
button_1.grid(row=1, column=0, pady=2)
button_2 = [Link](master=frame, text='2', padx=15,
pady=5, width=3, command=lambda: myclick(2))
button_2.grid(row=1, column=1, pady=2)
button_3 = [Link](master=frame, text='3', padx=15,
pady=5, width=3, command=lambda: myclick(3))
button_3.grid(row=1, column=2, pady=2)
button_4 = [Link](master=frame, text='4', padx=15,
pady=5, width=3, command=lambda: myclick(4))
button_4.grid(row=2, column=0, pady=2)
button_5 = [Link](master=frame, text='5', padx=15,
pady=5, width=3, command=lambda: myclick(5))
button_5.grid(row=2, column=1, pady=2)
button_6 = [Link](master=frame, text='6', padx=15,
pady=5, width=3, command=lambda: myclick(6))
button_6.grid(row=2, column=2, pady=2)
button_7 = [Link](master=frame, text='7', padx=15,
pady=5, width=3, command=lambda: myclick(7))
button_7.grid(row=3, column=0, pady=2)
button_8 = [Link](master=frame, text='8', padx=15,
pady=5, width=3, command=lambda: myclick(8))
button_8.grid(row=3, column=1, pady=2)
button_9 = [Link](master=frame, text='9', padx=15,
pady=5, width=3, command=lambda: myclick(9))
button_9.grid(row=3, column=2, pady=2)
button_0 = [Link](master=frame, text='0', padx=15,
pady=5, width=3, command=lambda: myclick(0))
button_0.grid(row=4, column=1, pady=2)
button_add = [Link](master=frame, text="+", padx=15,
pady=5, width=3, command=lambda: myclick('+'))
button_add.grid(row=5, column=0, pady=2)
button_subtract = [Link](
master=frame, text="-", padx=15, pady=5, width=3, command=lambda:
myclick('-'))
button_subtract.grid(row=5, column=1, pady=2)
button_multiply = [Link](
master=frame, text="*", padx=15, pady=5, width=3, command=lambda:
myclick('*'))
button_multiply.grid(row=5, column=2, pady=2)
button_div = [Link](master=frame, text="/", padx=15,
pady=5, width=3, command=lambda: myclick('/'))
button_div.grid(row=6, column=0, pady=2)
button_clear = [Link](master=frame, text="clear",
padx=15, pady=5, width=12, command=clear)
button_clear.grid(row=6, column=1, columnspan=2, pady=2)
button_equal = [Link](master=frame, text="=", padx=15,
pady=5, width=9, command=equal)
button_equal.grid(row=7, column=0, columnspan=3, pady=2)
[Link]()
Output:
ds use list of stack
# Python program to
# demonstrate stack implementation
# using list
stack = []
# append() function to push
# element in the stack
[Link]('a')
[Link]('b')
[Link]('c')
print('Initial stack')
print(stack)
# pop() function to pop
# element from stack in
# LIFO order
print('\nElements popped from stack:')
print([Link]())
print([Link]())
print([Link]())
print('\nStack after elements are popped:')
print(stack)
# uncommenting print([Link]())
# will cause an IndexError
# as the stack is now empty
[Link]
queue = []
[Link]('a')
[Link]('b')
[Link]('c')
print("Initial queue")
print(queue)
print("\nElements dequeued from queue")
print([Link](0))
print([Link](0))
print([Link](0))
print("\nQueue after removing elements")
print(queue)
Create a directory
# define the name of the directory to be created
path = "/tmp/year"
try :
[Link](path)
except OSError:
print ( "Creation of the directory %s failed" % path)
else :
print ( "Successfully created the directory %s " % path)
Creating a Directory with Subdirectories
import os
# define the name of the directory to be created
path = "/tmp/year/month/week/day"
try :
[Link](path)
except OSError:
print ( "Creation of the directory %s failed" % path)
else :
print ( "Successfully created the directory %s" % path)
Deleting a Directory
import os
# define the name of the directory to be deleted
path = "/tmp/year"
try :
[Link](path)
except OSError:
print ( "Deletion of the directory %s failed" % path)
else :
print ( "Successfully deleted the directory %s" % path)
other
import os
dirc = "Karlos"
parent_path = "D:/python"
abspath = [Link](parent_path, dirc)
[Link](abspath)
print("Creating directory '% s' Now" % dirc)
dirc = "Programming"
parent_path = "D:/python/bg"
mode = 0o666
abspath = [Link](parent_path, dirc)
[Link](abspath, mode)
print("Directory '% s' created together" % dirc)
Method 1: Deleting a directory
import os
# defining a name of the directory
abspath = "D:/python/Karlos"
try:
[Link](abspath)
except OSError:
print ("Deletion of the directory %s failed" % abspath)
else:
print ("Successfully deleted the directory %s" % abspath)