SD
SD
import tkinter as tk
import tkinter.messagebox
from tkinter.constants import SUNKEN
window = tk.Tk()
window.title('Calculator-GeeksForGeeks')
frame = tk.Frame(master=window, bg="skyblue", padx=10)
frame.pack()
entry = tk.Entry(master=frame, relief=SUNKEN, borderwidth=3, width=30)
entry.grid(row=0, column=0, columnspan=3, ipady=2, pady=2)
def myclick(number):
entry.insert(tk.END, number)
def equal():
try:
y = str(eval(entry.get()))
entry.delete(0, tk.END)
entry.insert(0, y)
except:
tkinter.messagebox.showinfo("Error", "Syntax Error")
def clear():
entry.delete(0, tk.END)
button_1 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(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 = tk.Button(master=frame, text='0', padx=15,
pady=5, width=3, command=lambda: myclick(0))
button_0.grid(row=4, column=1, pady=2)
button_subtract = tk.Button(
master=frame, text="-", padx=15, pady=5, width=3, command=lambda: myclick('-'))
button_subtract.grid(row=5, column=1, pady=2)
button_multiply = tk.Button(
master=frame, text="*", padx=15, pady=5, width=3, command=lambda: myclick('*'))
button_multiply.grid(row=5, column=2, pady=2)
window.mainloop()
program 2
def get_letter_grade(grade):
"""
This function converts a numerical grade to a letter grade.
Args:
grade: A numerical grade between 0 and 100.
Returns:
A letter grade (A, B, C, D, or F).
"""
def main():
"""
This function prompts the user for a numerical grade, calls the get_letter_grade
function to convert it, and prints the letter grade.
"""
try:
# Get the numerical grade from the user
number_grade = float(input("Enter your numerical grade (0-100): "))
if __name__ == "__main__":
main()
program2
M = int(input("Enter The Marks Of Maths(Out OF 100) "))
S = int(input("Enter The Marks Of Science(Out OF 100) "))
E = int(input("Enter The Marks Of English(Out OF 100) "))
TOT=M+S+E
print("Total Marks",TOT,sep=" ")
PER= (M+S+E)/3
print("Percentage",round(PER,2),sep=" ")
#Now I want The Below Code To Be Run Without The Use Of if_else
if(PER>50):
print("A")
elif(PER>0):
print("B")
elif(PER==0):
print("C")
while per > 50:
print("A")
break
is_a = PER > 50
is_b = PER <= 50 and PER > 0
is_c = PER == 0
# Since only one grade can evaluate to True, grade_values[True] will return the
correct grade
grade = grade_values[True]
print(grade)
program 2
def get_letter_grade(numeric_grade):
if numeric_grade >= 90:
return 'A'
elif numeric_grade >= 80:
return 'B'
elif numeric_grade >= 70:
return 'C'
elif numeric_grade >= 60:
return 'D'
elif numeric_grade >= 50:
return 'Fail'
else:
return 'G'
def main():
try:
# Get user input
numeric_grade = float(input("Enter your numeric grade: "))
if __name__ == "__main__":
main()
program 3
n = 5
for i in range(5):
for j in range(5):
print("*", end="")
print()
for i in range(5):
for j in range(i):
print(" ", end="")
for j in range(i, 5):
print("* ", end="")
print()
for i in range(5):
for j in range(5, i, -1):
print(" ", end="")
for k in range(i + 1):
print("* ", end="")
print()
n = 5
n = 5
for i in range(n):
for j in range(n):
if i == 0 or i == n - 1 or j == 0 or j == n - 1:
print("*", end="")
else:
print(" ", end="")
print()
program 4
# Python program to
# demonstrate stack implementation
# using list
stack = []
print('Initial stack')
print(stack)
# uncommenting print(stack.pop())
# will cause an IndexError
# as the stack is now empty
queue = []
queue.append('a')
queue.append('b')
queue.append('c')
print("Initial queue")
print(queue)
print("\nElements dequeued from queue")
print(queue.pop(0))
print(queue.pop(0))
print(queue.pop(0))
print("\nQueue after removing elements")
print(queue)
Ex no:3
if j == m//2-1 or j == m//2+1:
print('G', end=" ")
elif j == m//2:
print('F', end=" ")
else:
print(' ', end=" ")
print()
Ex no:3
n = 5
Ex no:3
# Python implementation
# to print circle pattern
import math
print()
# Driver code
radius = 6
printPattern(radius)
Ex no:4
# Python program to
# demonstrate stack implementation
# using list
stack = []
print('Initial stack')
print(stack)
Ex no:4
queue = []
queue.append('a')
queue.append('b')
queue.append('c')
print("Initial queue")
print(queue)
print("\nElements dequeued from queue")
print(queue.pop(0))
print(queue.pop(0))
print(queue.pop(0))
print("\nQueue after removing elements")
print(queue)
Ex no:4
Ex no:6
# importing os module
import os
# File name
file = 'file1.txt'
# File location
location = "D:/Pycharm projects/GeeksforGeeks/Authors/Nikhil/"
# Path
path = os.path.join(location, file)
Ex no:6
import os
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)