· 6 years ago · Apr 22, 2019, 05:08 PM
11.Write a python program to create a class Student whose objects have properties namely: Name, Roll number,Marks of 6 subjects and SGPA. Take user input to fill in the fields. Display the class of the student depending upon his sgpa. (>8 = Distinction; >6 & <8 = First Class; >4 & <6 = Second class, Else fail).If the candidate has failed, display the total number of subjects in which he/she has failed along with the list of subjects. Marks should be limited from 0 to 100.
2class Student:
3 def __init__(self):
4 self.name=input("Enter your name")
5 self.roll_no=int(input("Enter your roll_no"))
6 self.sub1=self.input_subjects()
7 self.sub2 = self.input_subjects()
8 self.sub3 = self.input_subjects()
9 self.sub4 = self.input_subjects()
10 self.sub5 = self.input_subjects()
11 self.sub6 = self.input_subjects()
12 def input_subjects(self):
13 n=int(input("Enter subject marks:"))
14 if(n<=100 and n>=0):
15 return n
16 else:
17 n=int(input("Enter correct marks:"))
18 while n not in range(0,101):
19 n=int(input("Enter correct marks:"))
20 return n
21
22 def check_marks(self,sub1,sub2,sub3,sub4,sub5,sub6):
23 subject=["Subject1","Subject2","Subject3","Subject4","Subject5","Subject6","Subject7"]
24 marks=[sub1,sub2,sub3,sub4,sub5,sub6]
25 fail_subject=[]
26 pass_subject=[]
27 for i,j in zip(marks,subject):
28 if i<40:
29 fail_subject.append([i,j])
30 else:
31 pass_subject.append([i,j])
32
33 if fail_subject==[]:
34 total=sub1+sub2+sub3+sub4+sub5+sub6
35 percent=(total/600)*100
36 if percent>80:
37 print("Name:",self.name,"Roll number",self.roll_no," Passed with distinction")
38 elif percent<80 and percent>60:
39 print("Name:",self.name,"Roll number",self.roll_no," Passed with First class")
40 elif percent<60 and percent>40:
41 print("Name:",self.name,"Roll number",self.roll_no," Passed with Second Class")
42 else:
43 print("Failed,Failed in subjects:")
44 for i in range(len(fail_subject)):
45 print(fail_subject[i][1])
46while(True):
47 st = Student()
48 #print("Name", st.name, "Roll no.", st.roll_no)
49 st.check_marks(st.sub1, st.sub2, st.sub3, st.sub4, st.sub5,st.sub6)
50 ch=input("Do you wish to continue Y/N?")
51 if(ch=='n' or ch=='N'):
52 break
53
542.Write a python program to create a class Employee whose objects have properties namely: Name, Id, Salary, Tax and Total Salary. Take user input to fill in the fields. Deduct Tax from Total Salary to get Salary. If Total Salary > 25000, tax = 10%, 25000<= Total Salary< 15000, Tax = 5%. If Total Salary <= 15000, then no tax.Display the Employee id, name and salary together.
55class Employee:
56 def __init__(self):
57 self.name=input("Enter your name")
58 self.id=int(input("Enter your ID"))
59 self.total_salary=int(input("Enter total salary"))
60 self.salary=0
61
62 def calc_salary(self,total_sal):
63 if total_sal>=25000:
64 tax=(total_sal*10)/100
65 self.salary=total_sal-tax
66 elif total_sal<25000 and total_sal>=15000:
67 tax = (total_sal * 5) / 100
68 self.salary = total_sal - tax
69 else:
70 self.salary=total_sal
71emp=Employee()
72emp.calc_salary(emp.total_salary)
73print("Name:",emp.name,"Id:",emp.id,"Salary",emp.salary)
74
753. Write a python program to read contents of a file and display them with and without punctuation marks. Store it in another file.
76import pickle
77f=open('demo.txt','w')
78n=int(input('How many lines in File?'))
79print('Enter Lines of your Choice: ')
80for i in range(n):
81 f.write(input())
82 f.write('\n')
83
84f.close()
85f=open('demo.txt','r')
86print('Your File with Punctuation Marks will look like: ')
87print(f.read())
88print('Without Punctuation, your file will look like this: ')
89
90f2=open('democopy.txt','w+')
91with open("demo.txt") as fileobj:
92 for line in fileobj:
93 for ch in line:
94 if ch.isalnum() or ch==' ' or ch=='\n':
95# print(ch,end='')
96 f2.write(ch)
97
98f2.seek(0,0)
99print(f2.read())
100f.close()
101f2.close()
102
1034.Write a python program to implement a student class having object properties as name, rollno, marks. Take input of 5 students from the user. Store it in a file and display the contents of the file one by one.
104import pickle
105class Student:
106 def __init__(self):
107 self.name=input("Enter your name")
108 self.roll_number=int(input("Enter your roll_number"))
109 self.marks1=int(input("Enter your marks in subject 1"))
110 self.marks2 = int(input("Enter your marks in subject 2"))
111 self.marks3 = int(input("Enter your marks in subject 3"))
112
113 def display(self):
114 print("Name:",self.name,"Roll_number:",self.roll_number,"Marks1",self.marks1,"Marks2",self.marks2,"Marks3",self.marks3)
115
116with open("Students.txt","a+b") as f:
117 n=1
118 while n<=5:
119 st=Student()
120 pickle.dump(st,f)
121 n=n+1
122 print("Reading the contents of file:")
123 f.seek(0,0)
124 while 1:
125 try:
126 temp=pickle.load(f)
127 temp.display()
128 except EOFError:
129 print("End of file")
130 break
131
1325.Write a python program to draw scenery with a house using tkinter.
133from tkinter import *
134root=Tk()
135c=Canvas(root,height=500,width=500,bg="light blue")
136c.pack()
137c.create_line(0,400,500,400)
138c.create_rectangle(300,300,400,400,fill="wheat",activefill="red")
139c.create_polygon(300,300,350,230,400,300,fill="wheat",activefill="red",outline="black")
140c.create_arc(5,350,100,450,start=0,extent=180,fill="green")
141c.create_arc(100,350,195,450,start=0,extent=180,fill="green")
142c.create_arc(195,350,300,450,start=0,extent=180,fill="green")
143c.create_arc(400,350,500,450,start=0,extent=180,fill="green")
144c.create_oval(100,50,200,150,fill="yellow",outline="orange",width=2)
145c.create_text(350,350,text="Home",font=("Times",13,"bold"))
146'''img=PhotoImage(file="joker")
147c.create_image(500,0,image=img,anchor=NE)
148‘’’
149root.mainloop()
150
151
1526. Write a python program to create a login form using tkinter. It should display the username upon successful login and clear details when “reset†button is pressed.
153
154from tkinter import *
155root = Tk()
156root.geometry('500x500')
157root.title("Registration Form")
158
159label_1 = Label(root, text="Enter your username",width=20,font=("bold", 10))
160label_1.place(x=80,y=130)
161
162entry_1 = Entry(root)
163entry_1.place(x=240,y=130)
164
165
166label_2 = Label(root, text="Enter your password",width=20,font=("bold", 10))
167label_2.place(x=68,y=180)
168
169entry_2 = Entry(root)
170entry_2.place(x=240,y=180)
171
172label_4 = Label(root, text="",width=20,font=("bold", 10))
173label_4.place(x=150,y=250)
174
175label_5 = Label(root, text="",width=20,font=("bold", 10))
176label_5.place(x=150,y=300)
177
178label_6 = Label(root, text="",width=20,font=("bold", 10))
179label_6.place(x=150,y=325)
180
181def login():
182 label_4["text"]=entry_1.get()
183 #label_5["text"]=entry_2.get()
184 label_5.config(text=entry_2.get())
185 label_6.config(text="Login Successful")
186def reset():
187 label_4["text"]=""
188 label_5["text"] = ""
189 label_6.config(text="")
190 entry_1.delete(0, 'end')
191 entry_2.delete(0, 'end')
192b1=Button(text="Login",command= login).place(x=100,y=350)
193b2=Button(text="RESET",command= reset).place(x=300,y=350)
194root.mainloop()
195
1967. Write a python program to change the background of a frame using four colour buttons placed at four corners of the frame
197from tkinter import *
198r=Tk()
199r.title("Change Bg")
200f=Frame(r,width=400,height=400,bg='ghost white')
201f.grid()
202f.propagate(0)
203def handle(x):
204 if x=='red':
205 f['bg']='red'
206 elif x=='blue':
207 f['bg'] = 'blue'
208 elif x=='green':
209 f['bg'] = 'green'
210 elif x=='yellow':
211 f['bg'] = 'yellow'
212
213b1=Button(f,text='Red',bg='white',fg='black',command=lambda:handle('red'))
214b1.place(x=5,y=5)
215
216b1=Button(f,text='blue',bg='white',fg='black',command=lambda:handle('blue'))
217b1.place(x=350,y=5)
218
219b1=Button(f,text='green',bg='white',fg='black',command=lambda:handle('green'))
220b1.place(x=5,y=360)
221
222b1=Button(f,text='yellow',bg='white',fg='black',command=lambda:handle('yellow'))
223b1.place(x=350,y=360)
224r.mainloop()
225
2268.Write a python program to develop a Multiple Choice Quiz which displays a message of success when correct option is selected by the user. (Hint: Use Radiobutton)
227import tkinter as tk
228from tkinter import ttk
229
230root=tk.Tk()
231root.title("Quiz")
232
233info_label=ttk.Label(root, text='Select the correct option')
234info_label.grid(row=0,column=0)
235
236# question1 label
237que1_label=ttk.Label(root, text='2+3= ?')
238que1_label.grid(row=1, column=0, columnspan=3, sticky=tk.W)
239
240# question 1 options
241usertype=tk.IntVar()
242
243radiobtn1=ttk.Radiobutton(root, text='1', value=1, variable=usertype)
244radiobtn1.grid(row=2, column=0)
245
246radiobtn2=ttk.Radiobutton(root, text='4', value=4,variable=usertype)
247radiobtn2.grid(row=3, column=0)
248
249radiobtn3=ttk.Radiobutton(root, text='5', value=5, variable=usertype)
250radiobtn3.grid(row=4, column=0)
251
252radiobtn4=ttk.Radiobutton(root, text='6', value=6, variable=usertype)
253radiobtn4.grid(row=5, column=0)
254
255output_label=ttk.Label(root)
256output_label.grid(row=8, column=0, sticky=tk.W)
257
258def action():
259 if usertype.get() == 5:
260 output_label.config(text='Success!!!')
261 else:
262 output_label.config(text='Wrong answer')
263
264submit_button= ttk.Button(root, text='Submit', command=action)
265submit_button.grid(row=7, column=0, sticky=tk.W)
266
267def clear():
268 output_label.config(text='')
269
270clear_button= ttk.Button(root, text='Answer again', command=clear)
271clear_button.grid(row=7, column=1, sticky=tk.W)
272
273root.mainloop()
274
275
2769.Write a python program to develop a Basket App. The App allows user to add multiple fruits from the given set of fruits.
277from tkinter import *
278r = Tk()
279f = Frame(r)
280f.pack()
281applecount = 0
282
283
284def acount(x):
285 global applecount
286 if x == 'add':
287 applecount = applecount + 1
288 l1.config(text=applecount)
289 elif x == 'sub':
290 applecount = applecount - 1
291 if applecount < 0:
292 l1.config(text='You cant choose fruits in negative quatities')
293 else:
294 #applecount = applecount - 1
295 l1.config(text=applecount)
296
297
298Applelabel = Label(f, text='Apples')
299Applelabel.pack()
300add1 = Button(f, text='+', command=lambda: acount('add'))
301add1.pack()
302sub1 = Button(f, text='-', command=lambda: acount('sub'))
303sub1.pack()
304l1 = Label(f)
305l1.pack()
306
307mangocount = 0
308
309
310def mcount(x):
311 global mangocount
312 if mangocount < 0:
313 l2.config(text='You cant choose fruits in negative quatities')
314 else:
315 if x == 'add':
316 mangocount = mangocount + 1
317 l2.config(text=mangocount)
318 elif x == 'sub':
319 mangocount = mangocount - 1
320 if mangocount < 0:
321 l2.config(text='You cant choose fruits in negative quatities')
322 else:
323 #mangocount = mangocount - 1
324 l2.config(text=mangocount)
325
326
327mangolabel = Label(f, text='Mango')
328mangolabel.pack()
329add2 = Button(f, text='+', command=lambda: mcount('add'))
330add2.pack()
331sub2 = Button(f, text='-', command=lambda: mcount('sub'))
332sub2.pack()
333l2 = Label(f)
334l2.pack()
335
336orangecount = 0
337
338
339def ocount(x):
340 global orangecount
341 if x == 'add':
342 orangecount = orangecount + 1
343 l3.config(text=orangecount)
344 elif x == 'sub':
345 orangecount = orangecount - 1
346 if orangecount < 0:
347 l3.config(text='You cant choose fruits in negative quatities')
348 else:
349 #orangecount = orangecount - 1
350 l3.config(text=orangecount)
351
352
353orangelabel = Label(f, text='Orange')
354orangelabel.pack()
355add3 = Button(f, text='+', command=lambda: ocount('add'))
356add3.pack()
357sub3 = Button(f, text='-', command=lambda: ocount('sub'))
358sub3.pack()
359l3 = Label(f)
360l3.pack()
361
362r.mainloop()
363
36410.Write a python program which displays formula of a geometrical shape when the shape is active. Take square, triangle, circle and rectangle as the four shapes.
365from tkinter import *
366r=Tk()
367c=Canvas(r,width=500,height=500)
368c.pack()
369
370def formula():
371 print('Square!!!!')
372c.create_rectangle(10,10,110,110,fill='red')
373c.create_text(22,45,text='Area=\nside x side',anchor='w',fill='red',activefill='black')
374c.create_rectangle(120,10,250,110,fill='lightblue')
375c.create_text(122,45,text='Area=\nlength x breadth',anchor='w',fill='lightblue',activefill='black')
376c.create_polygon(260,110,310,10,360,110,fill='lightgreen')
377c.create_text(300,75,text='Area\n=\n0.5 \nx base \nx height',anchor='w',fill='lightgreen',activefill='black')
378c.create_oval(370,10,470,110,fill='yellow')
379c.create_text(375,50,text='Area=\n3.14 X radius X \nradius',anchor='w',fill='yellow',activefill='black')
380
381r.mainloop()
382
38311. circle calculation
384from tkinter import *
385r=Tk()
386r.geometry('400x400+100+100')
387r.title("Area Calculation")
388
389def cir():
390 rad=txtlab1.get()
391 area=(3.142)*int(rad)*int(rad)
392 txtlab3.delete(0,END)
393 txtlab3.insert(END, area)
394
395frame=Frame(r)
396frame.grid()
397butframe=Frame(frame,height=100,width=400,bd=2,bg="cadet blue",padx=10,pady=10)
398butframe.pack(side=BOTTOM)
399data=Frame(frame,height=300,width=400,bd=2,bg="ghost white",padx=10,pady=10)
400data.pack(side=TOP)
401but1=Button(butframe,height=5,width=7,text='Calculate',relief=RIDGE,bg="ghost white",padx=10,pady=10,command= cir)
402but1.grid(row=0,column=0)
403
404lab1=Label(data,height=3,width=7,text='Radius',bg="ghost white",relief=RIDGE)
405lab1.grid(row=0,column=0)
406txtlab1=Entry(data,width=10,font=('arial','20','bold'),relief=RIDGE)
407txtlab1.grid(row=0,column=1)
408
409txtlab3=Entry(butframe,width=10,font=('arial','20','bold'),relief=RIDGE)
410txtlab3.grid(row=2,column=0)
411
412r.mainloop()
413
41412. square calculation
415from tkinter import *
416r=Tk()
417r.geometry('400x400+100+100')
418r.title("Area Calculation")
419
420def squ():
421 side=txtlab1.get()
422 area=int(side)*int(side)
423 txtlab3.delete(0,END)
424 txtlab3.insert(END, area)
425
426frame=Frame(r)
427frame.grid()
428butframe=Frame(frame,height=100,width=400,bd=2,bg="cadet blue",padx=10,pady=10)
429butframe.pack(side=BOTTOM)
430data=Frame(frame,height=300,width=400,bd=2,bg="ghost white",padx=10,pady=10)
431data.pack(side=TOP)
432but1=Button(butframe,height=5,width=7,text='Calculate',relief=RIDGE,bg="ghost white",padx=10,pady=10,command=squ)
433but1.grid(row=0,column=0)
434
435lab1=Label(data,height=3,width=7,text='Side',bg="ghost white",relief=RIDGE)
436lab1.grid(row=0,column=0)
437txtlab1=Entry(data,width=10,font=('arial','20','bold'),relief=RIDGE)
438txtlab1.grid(row=0,column=1)
439
440txtlab3=Entry(butframe,width=10,font=('arial','20','bold'),relief=RIDGE)
441txtlab3.grid(row=2,column=0)
442
443r.mainloop()
444
445
44613. rectangle calculation
447from tkinter import *
448r=Tk()
449r.geometry('400x400+100+100')
450r.title("Area Calculation")
451
452def rec():
453 len=txtlab1.get()
454 bred=txtlab2.get()
455 area=int(bred)*int(len)
456 txtlab3.delete(0,END)
457 txtlab3.insert(END, area)
458
459frame=Frame(r)
460frame.grid()
461butframe=Frame(frame,height=100,width=400,bd=2,bg="cadet blue",padx=10,pady=10)
462butframe.pack(side=BOTTOM)
463data=Frame(frame,height=300,width=400,bd=2,bg="ghost white",padx=10,pady=10)
464data.pack(side=TOP)
465but1=Button(butframe,height=5,width=7,text='Calculate',relief=RIDGE,bg="ghost white",padx=10,pady=10,command=rec)
466but1.grid(row=0,column=0)
467
468lab1=Label(data,height=3,width=7,text='Length',bg="ghost white",relief=RIDGE)
469lab1.grid(row=0,column=0)
470txtlab1=Entry(data,width=10,font=('arial','20','bold'),relief=RIDGE)
471txtlab1.grid(row=0,column=1)
472lab2=Label(data,height=3,width=7,text='Breadth',bg="ghost white",relief=RIDGE)
473lab2.grid(row=1,column=0)
474txtlab2=Entry(data,width=10,textvariable='name',font=('arial','20','bold'),relief=RIDGE)
475txtlab2.grid(row=1,column=1)
476
477txtlab3=Entry(butframe,width=10,font=('arial','20','bold'),relief=RIDGE)
478txtlab3.grid(row=2,column=0)
479
480r.mainloop()
481
482
48314.Triangle Calculation
484from tkinter import *
485r=Tk()
486r.geometry('400x400+100+100')
487r.title("Area Calculation")
488
489def tri():
490 base=txtlab1.get()
491 height=txtlab2.get()
492 area=(1/2)*int(base)*int(height)
493 txtlab3.delete(0,END)
494 txtlab3.insert(END, area)
495
496frame=Frame(r)
497frame.grid()
498butframe=Frame(frame,height=100,width=400,bd=2,bg="cadet blue",padx=10,pady=10)
499butframe.pack(side=BOTTOM)
500data=Frame(frame,height=300,width=400,bd=2,bg="ghost white",padx=10,pady=10)
501data.pack(side=TOP)
502but1=Button(butframe,height=5,width=7,text='Calculate',relief=RIDGE,bg="ghost white",padx=10,pady=10,command=tri)
503but1.grid(row=0,column=0)
504
505lab1=Label(data,height=3,width=7,text='Height',bg="ghost white",relief=RIDGE)
506lab1.grid(row=0,column=0)
507txtlab1=Entry(data,width=10,font=('arial','20','bold'),relief=RIDGE)
508txtlab1.grid(row=0,column=1)
509lab2=Label(data,height=3,width=7,text='Width',bg="ghost white",relief=RIDGE)
510lab2.grid(row=1,column=0)
511txtlab2=Entry(data,width=10,textvariable='name',font=('arial','20','bold'),relief=RIDGE)
512txtlab2.grid(row=1,column=1)
513
514txtlab3=Entry(butframe,width=10,font=('arial','20','bold'),relief=RIDGE)
515txtlab3.grid(row=2,column=0)
516
517r.mainloop()
518
519
520
52115.Write a python program to determine whether the string input by the user is a palindrome or not. The input should be taken from the user on a UI and the output should be displayed on the UI
522from tkinter import *
523from tkinter import ttk
524
525root=Tk()
526root.configure(background="powder blue")
527root.title("To check string is pallindrome or not")
528root.geometry("500x400")
529
530l=ttk.Label(root,text="Enter string", background="powder blue", font=("arial",14,"bold"))
531l.grid(row=0, column=0, sticky=W)
532
533l_var=StringVar()
534l_entry=ttk.Entry(root, textvariable=l_var, font=("arial",14,"bold"), background="powder blue", width=20)
535l_entry.grid(row=0, column=1, padx=20,sticky=W)
536
537
538def action():
539 s=l_var.get()
540 p=s[::-1] #reverse of string is stored in p
541
542 for (k,q) in zip(s,p):
543 flag=0
544 if k!=q:
545 flag=1
546 break
547
548 if flag==0:
549 l2=ttk.Label(root,text="PALLINDROME", background="powder blue", font=("arial",14,"bold"))
550 l2.grid(row=5, column=0, sticky=W)
551
552 if flag==1:
553 l2=ttk.Label(root,text=" NOT PALLINDROME", background="powder blue", font=("arial",14,"bold"))
554 l2.grid(row=5, column=0, sticky=W)
555check=Button(root, command=action,font=("arial",12,"bold"), text="CHECK")
556check.grid(row=3,column=0,sticky=W)
557
558root.mainloop()
559
56016. Develop a UI to implement addition and subtraction of two numbers taken as input from the user.UI should display sum of the numbers when “ADD†button is clicked and should display its subtraction when “SUB†button is clicked.
561from tkinter import *
562from tkinter import ttk
563
564r=Tk()
565r.title("Add subtract")
566
567label1=ttk.Label(r,text="Enter first number")
568label1.grid(row=1,column=2)
569
570entry1=ttk.Entry(r)
571entry1.grid(row=1,column=5)
572
573label2=ttk.Label(r,text="Enter second number")
574label2.grid(row=2,column=2)
575
576entry2=ttk.Entry(r)
577entry2.grid(row=2,column=5)
578
579label3=ttk.Label(r,text="")
580label3.grid(row=3,column=2)
581
582def add():
583 label3.config(text='')
584 var = str(int(entry1.get()) + int(entry2.get()))
585 label3.config(text=("Sum is "+var))
586
587def subtract():
588 label3.config(text='')
589 var = str(int(entry1.get()) - int(entry2.get()))
590 label3.config(text=("Difference is "+var))
591
592def clear():
593 label3.config(text="")
594 entry1.delete(0,'end')
595 entry2.delete(0, 'end')
596button1=ttk.Button(r,text="Add",command=add)
597button1.grid(row=8,column=2)
598
599button3=ttk.Button(r,text="Subtract",command=subtract)
600button3.grid(row=10,column=2)
601
602button2=ttk.Button(r,text="Clear",command=clear)
603button2.grid(row=12,column=2)
604r.mainloop()
605
606
607
60818. Write a python program to add multiple employee records in the employee table having columns. EmpId EmpName Basic HRA DA PF EmpSalary
609Calculate the gross salary and display it for all the employees
610import sqlite3
611conn = sqlite3.connect('Employee_detail1.db')
612cursor = conn.cursor()
613cursor.execute('CREATE TABLE IF NOT EXISTS Employee (Eno int,Ename varchar,Basic float,HRA float,DA float,PF float,Dno int,Dname varchar )')
614
615while True:
616 print("1. New entry\n2. View details\n3. Gross Salary ")
617 ch = int(input("Enter decision [1/2/3]: "))
618 if ch == 1:
619 n = int(input("Enter no of Employees"))
620 for i in range(n):
621 Eno = int(input("Enter Id of Employee" + str(i + 1) + ":"))
622 Ename = input("Enter Employee Name" + str(i + 1) + ":")
623 Basic = float(input("Enter Salary of employee" + str(i + 1) + ":"))
624 HRA = 0.1 * Basic
625 DA = 0.5 * Basic
626 PF = 0.05 * Basic
627 Dno = int(input("Enter Department No" + ":"))
628 Dname = input("Enter Department Name" + ":")
629 cursor = conn.cursor()
630 tup1 = (Eno, Ename, Basic, HRA, DA, PF, Dno, Dname)
631 query1 = ('INSERT INTO Employee (Eno,Ename,Basic,HRA,DA,PF,Dno,Dname) VALUES("%d","%s","%f","%f","%f","%f","%d","%s")')
632 cursor.execute(query1 % tup1)
633 conn.commit()
634
635 elif ch == 2:
636 cursor.execute("SELECT * FROM Employee")
637 print(cursor.fetchall())
638 elif ch == 3:
639 print("Gross Salary")
640 cursor.execute("SELECT Ename,(Basic+HRA+DA+PF) As Gross_sal from Employee GROUP BY Ename")
641 print(cursor.fetchall())
642 else:
643 break
644
645
64619, 20, 21. Write a python program to add multiple and display all the employee records in the employee table having columns
647EmpId EmpName EmpDept EmpSalary Experience
648Write a python program to increase employee salary by 10% in the employee table having columnsEmpId EmpName EmpDept EmpSalary Experience
649
650import sqlite3
651conn=sqlite3.connect(database='Employee.db')
652c=conn.cursor()
653while True:
654 choice=int(input("Choose an Option: \n1.Insert\t2.View\t3.Increase Salary\t4.Exit\n"))
655 if choice==1:
656 c.execute("create table if not exists Employee(EmpId int primary key, EmpName varchar(30),EmpDept varchar(30),EmpSalary int,Experience varchar(30))")
657 name=input('Name:')
658 eid=int(input('ID:'))
659 dep=input('Department:')
660 sal=int(input('Salary:'))
661 ep=input('Experience:')
662 qi="insert into Employee(EmpId , EmpName,EmpDept,EmpSalary,Experience) values ('%d','%s','%s','%d','%s')"
663 c.execute(qi%(eid,name,dep,sal,ep))
664 conn.commit()
665
666
667 if choice ==2:
668 qv="select * from Employee"
669 c.execute(qv)
670 print(c.fetchall())
671
672
673 if choice ==3:
674 up_id=int(input('Enter the ID of Employee '))
675
676
677 qu="update Employee set EmpSalary= 1.1*EmpSalary where EmpId='%d' "
678 c.execute(qu%(up_id))
679 conn.commit()
680
681
682 if choice ==4:
683 break
684
685conn.commit() #Commits the changes to database
686conn.close() #Closes the database connection
687
688
689
690CALCULATOR(NOT IN QB)
691from tkinter import *
692r=Tk()
693r.geometry("300x400+100+100")
694r.title("Calculator")
695frame=Frame(r)
696frame.pack()
697
698###functions
699def equals():
700 fetch=txt.get()
701 try:
702 # evaluate the expression using the eval function
703 value=eval(fetch)
704 except SyntaxError or NameError:
705 txt.delete(0, END)
706 txt.insert(0, 'Invalid Input!')
707 else:
708 txt.delete(0, END)
709 txt.insert(0, value)
710def action(var):
711 txt.insert(END, var)
712
713def clearAC():
714 txt.delete(0, END)
715
716def dele():
717 e = txt.get()[:-1]
718 txt.delete(0, END)
719 txt.insert(0, e)
720
721###display field
722txt=Entry(frame,font=('arial','12'))
723txt.grid(row=0,column=0,columnspan=6,pady=3,padx=10)
724txt.focus_set()
725
726####Buttons
727b1=Button(frame,text='AC',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=clearAC)
728b1.grid(row=2,column=2)
729b1=Button(frame,text='C',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=clearAC)
730b1.grid(row=2,column=3)
731b1=Button(frame,text='Del',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=dele)
732b1.grid(row=2,column=4)
733b1=Button(frame,text='0',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('0'))
734b1.grid(row=6,column=1)
735b1=Button(frame,text='1',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('1'))
736b1.grid(row=5,column=0)
737b1=Button(frame,text='2',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('2'))
738b1.grid(row=5,column=1)
739b1=Button(frame,text='3',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('3'))
740b1.grid(row=5,column=2)
741b1=Button(frame,text='4',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('4'))
742b1.grid(row=4,column=0)
743b1=Button(frame,text='5',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('5'))
744b1.grid(row=4,column=1)
745b1=Button(frame,text='6',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('6'))
746b1.grid(row=4,column=2)
747b1=Button(frame,text='7',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('7'))
748b1.grid(row=3,column=0)
749b1=Button(frame,text='8',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('8'))
750b1.grid(row=3,column=1)
751b1=Button(frame,text='9',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('9'))
752b1.grid(row=3,column=2)
753b1=Button(frame,text='+',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('+'))
754b1.grid(row=3,column=3)
755b1=Button(frame,text='-',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('-'))
756b1.grid(row=3,column=4)
757b1=Button(frame,text='*',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('*'))
758b1.grid(row=4,column=3)
759b1=Button(frame,text='/',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('/'))
760b1.grid(row=4,column=4)
761b1=Button(frame,text='%',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('%'))
762b1.grid(row=6,column=2)
763b1=Button(frame,text='.',height=2,width=5,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=lambda:action('.'))
764b1.grid(row=6,column=0)
765b1=Button(frame,text='=',height=5,width=10,padx=1,pady=1,bg='Ghost white',relief=RIDGE,command=equals)
766b1.grid(row=5,column=3,rowspan=2,columnspan=2)
767
768r.mainloop()