Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Week 1/SET 11/Task-5.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
print("Enter the exam marks:")
marks=[]
tot = 0
print("Enter Marks Obtained in different exams: ")
for i in range(5):
marks.insert(i, input())
#print(marks[i])

for i in range(5):
tot = tot + int(marks[i])
tot = sum(int(marks[i]) for i in range(5))
Comment on lines -3 to +8
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 3-10 refactored with the following changes:

avg = tot/5
print("The average is :",avg)
if avg >=90 :
Expand Down
4 changes: 1 addition & 3 deletions Week 1/SET 14/ques4.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
def sumofDigits(n):
sum = 0
for digit in str(n):
sum += int(digit)
sum = sum(int(digit) for digit in str(n))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sumofDigits refactored with the following changes:

print(sum)

n =input()
Expand Down
8 changes: 4 additions & 4 deletions Week 2/SET 11/q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def binaryToDecimal(n):
num = n;
dec_value = 0;
base = 1;

temp = num;
while(temp):
while (temp):
last_digit = temp % 10;
temp = int(temp / 10);

dec_value += last_digit * base;
base = base * 2;
base *= 2;
Comment on lines -40 to +47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function binaryToDecimal refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

return dec_value;

if n == 1:
Expand Down
6 changes: 3 additions & 3 deletions Week 2/SET 11/q2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
def pascal_triangle(num):
row = [1]
y = [0]
for x in range(max(num,0)):
print(row)
row=[l+r for l,r in zip(row+y, y+row)]
for _ in range(max(num,0)):
print(row)
row=[l+r for l,r in zip(row+y, y+row)]
Comment on lines -7 to +9
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function pascal_triangle refactored with the following changes:

return num>=1
pascal_triangle(n)
12 changes: 6 additions & 6 deletions Week 2/SET 11/q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# value a list from 11-20, 21-30, and 31-40 respectively. Access the fifth value of each key
# from the dictionary.

m = dict()
m = {}
li = ['x','y','z']
s = 11;
for l in li:
val = list()
for i in range(9):
val = []
for _ in range(9):
val.append(s)
s+=1
s = s+1
s += 1
m[l] = val
print(m)
for k in m.keys():
print(m[k][4])
for k, v in m.items():
print(v[4])
18 changes: 8 additions & 10 deletions Week 2/SET 11/q5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,25 @@
a = [1,2,3,4,5,6,4]
b = [9,8,7,6,5,4,3]

m = dict()
m = {}

if(len(a) >= len(b)):
for i in range(len(a)):
if (len(a) >= len(b)):
for i in range(len(a)):
if i < len(b):
if a[i] in m.keys():
if a[i] in m:
m[a[i]].append(b[i])
else:
val = list()
val.append(b[i])
val = [b[i]]
m[a[i]] = val
else:
m[a[i]] = None
else:
for i in range(len(b)):
for i in range(len(b)):
if i < len(a):
if b[i] in m.keys():
if b[i] in m:
m[b[i]].append(a[i])
else:
val = list()
val.append(a[i])
val = [a[i]]
Comment on lines -8 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 8-28 refactored with the following changes:

m[b[i]] = val
else:
m[b[i]] = None
Expand Down
6 changes: 1 addition & 5 deletions Week 2/SET 14/ques1.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
def ispangram(str):
alphabet = "abcdefghijklmnopqrstuvwxyz"
for char in alphabet:
if char not in str.lower():
return False

return True
return all(char in str.lower() for char in alphabet)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ispangram refactored with the following changes:


str = input("enter a sentence :\n ")
if ispangram(str):
Expand Down
3 changes: 1 addition & 2 deletions Week 3/SET 14/ques2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ def __init__(self):
pass

def _getString(self):
s = input()
return s
return input()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ques2._getString refactored with the following changes:


def _printString(self,s):
print(s.upper())
Expand Down
2 changes: 1 addition & 1 deletion Week 3/SET 5/Task-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Student:
def __init__(self):
self.name = input("Enter your name:")
self.roll = int(input("Enter your roll number:"))
self.marks=list()
self.marks = []
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Student.__init__ refactored with the following changes:

for i in range (5):
self.marks.insert(i,int(input("enter %d th mark :"%(i+1))))

Expand Down
24 changes: 6 additions & 18 deletions Week 3/SET 5/Task-4.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@
print("Which package do you have A, B, or C? : ")
package =str(input())

if(package == 'A'or package == 'B'or package == 'C'):
if package in {'A', 'B', 'C'}:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 5-36 refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Replace if statement with if expression (assign-if-exp)
  • Replace multiple comparisons of same variable with in operator (merge-comparisons)
  • Use set when checking membership of a collection of literals (collection-into-set)

print("How many hours were used:")
hours=int(input())
if(hours > 744 or hours < 0):
print("Hours cannot be greater than 744 or less than 0!! \n\n")
print("Enter hours again: ")
hours=int(input())

if(package == "A"):

if package == "A":
limit = 9.95;

if(hours < 10):
total = limit;

else:
total = ((hours - 10) * 2) + limit

total = limit if (hours < 10) else ((hours - 10) * 2) + limit
print("The amount due is: $%.2f"%total)

if(package == 'B'):

elif package == 'B':
limit = 14.95;
if(hours < 20):
total = limit;
else:
total = ((hours - 20) * 1) + limit;

total = limit if (hours < 20) else ((hours - 20) * 1) + limit
print("The amount due is: $%.2f"%total)

if(package == 'C'):

elif package == 'C':
limit = 19.95;
total = limit;
print("The amount due is: $%.2f"%total)
2 changes: 1 addition & 1 deletion Week 3/SET 5/Task-5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def main():
height = int(input('Please enter your height in inches: '))

# Calculate the BMI (BMI = weight*703/height^2)
BMI = (weight * 703.0) / (height*height)
BMI = weight * 703.0 / height**2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print ('Your BMI is %.1f'%BMI)

# Determine whether the user is underweight, overweight, or optimal
Expand Down
24 changes: 10 additions & 14 deletions Week 4/SET1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@
dob=tk.Label(window, text="DATE OF BIRTH", bg='#6449C6', fg='white', pady=15)
dob.place(x=13, y=75)

monthchosen = Combobox(window, width = 7)
daychosen = Combobox(window, width = 7)
monthchosen = Combobox(window, width = 7)
daychosen = Combobox(window, width = 7)
yearchosen = Combobox(window, width = 7)


dayl=[]
for i in range(0 ,32):
dayl.append(str(i))
dayl = [str(i) for i in range(32)]
dayl[0]='Day:'
daychosen['values'] = dayl

yearl=[]
for i in range(1968 ,2022):
yearl.append(str(i))
yearl = [str(i) for i in range(1968 ,2022)]
yearl[0]='Year:'
yearchosen['values'] = yearl

Comment on lines -32 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 32-139 refactored with the following changes:

monthchosen['values'] = ('Month:',
' January',
' February',
Expand All @@ -59,11 +55,11 @@
' October',
' November',
' December')
daychosen.current(0)

daychosen.current(0)
daychosen.place(x=150, y=88)

monthchosen.current(0)
monthchosen.current(0)
monthchosen.place(x=220, y=88)

yearchosen.current(0)
Expand Down Expand Up @@ -133,10 +129,10 @@
f1=tk.Label(window, text="COUNTRY", bg='#6449C6', fg='white', padx=10, pady=15)
f1.place(x=5, y=428)

countrychosen = Combobox(window, width = 7)
countrychosen = Combobox(window, width = 7)
c=["India", "Malaysia", "Japan", "U.S.", "Germany"]
countrychosen['values'] = c
countrychosen.current(0)
countrychosen.current(0)
countrychosen.place(x=150, y=440)

f1=tk.Label(window, text="HOBBIES", bg='#6449C6', fg='white', padx=10, pady=15)
Expand Down
18 changes: 7 additions & 11 deletions Week-5/Set4-hotelwithdatabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ def database():

def display():
db=sqlite3.connect('hotel.db')

with db:
cursor=db.cursor()
my_w = tk.Tk()
my_w.geometry("600x250")

r_set=cursor.execute('''SELECT * from HOTEL ''');
i=0
for HOTEL in r_set:
for i, HOTEL in enumerate(r_set):
for j in range(len(HOTEL)):
e = Entry(my_w, width=10, fg='blue')
e.grid(row=i, column=j)
e.insert(END, HOTEL[j])
i=i+1
Comment on lines -59 to -72
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function display refactored with the following changes:

a = Label(window ,text = "Title ").grid(row = 0,column = 0,sticky = "NSEW")
b = Label(window ,text = "First Name ").grid(row = 1,column = 0,sticky = "NSEW")
c = Label(window ,text = "Last Name ").grid(row = 2,column = 0,sticky = "NSEW")
Expand Down Expand Up @@ -119,7 +117,7 @@ def display():
line2 = Label(window, text="Total amount payable ZAR__ x_ nights = ZAR__ due to Arabella\n Hotel and Spa", bg="white")
line3 = Label(window, text="Credit Card will be charged on receipt of this form and details will also be used to settle all incidentals not settle on\n departure. A copy of the final folio will be sent to you should there be any unsettled charges.", bg="white")
line4 = Label(window, text="In order to qualify for the above rates, your booking needs to be made on or before 15th January 2016", bg="white")
line5 = Label(window, text="Terms and conditions can be found on the next page.", bg="white")
line5 = Label(window, text="Terms and conditions can be found on the next page.", bg="white")
Comment on lines -122 to +120
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 122-190 refactored with the following changes:

This removes the following comments ( why? ):

# row value inside the loop

line6 = Label(window, text="The rate is valid for seven days before and after the conference dates. Check in time is 14:00 & check out time is 11:00", bg="white")
line7 = Label(window, text="By your signature hereto, you are accepting all terms and conditions specified on this form and confirm that all information\n given is current and accurate.", bg="white")

Expand Down Expand Up @@ -169,23 +167,21 @@ def display():
p103.grid(row = 28,column = 1,sticky = "NSEW")

btn = Button(window ,text="SUBMIT",command = database,width=20).grid(row=30,column=2)
btn = Button(window,text="DISPLAY RECORD(s)",command=display,width=20).grid(row=30,column=3)
btn = Button(window,text="DISPLAY RECORD(s)",command=display,width=20).grid(row=30,column=3)
window.mainloop()

import sqlite3
my_conn = sqlite3.connect('hotel.db')

import tkinter as tk
from tkinter import *
import tkinter as tk
from tkinter import *
my_w = tk.Tk()
my_w.geometry("1300x250")

r_set=my_conn.execute('''SELECT * from HOTEL ''');
i=0 # row value inside the loop
for HOTEL in r_set:
for i, HOTEL in enumerate(r_set):
for j in range(len(HOTEL)):
e = Entry(my_w, width=10, fg='blue')
e.grid(row=i, column=j)
e.insert(END, HOTEL[j])
i=i+1
my_w.mainloop()
4 changes: 1 addition & 3 deletions Week-5/displaySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
my_w.geometry("1300x250")
my_w.title("Database")
r_set = my_conn.execute('''SELECT * from STFORM3 ''')
i = 0 # row value inside the loop
for STFORM3 in r_set:
for i, STFORM3 in enumerate(r_set):
for j in range(len(STFORM3)):
e = Entry(my_w, width=10, fg='black')
e.grid(row=i, column=j)
e.insert(END, STFORM3[j])
i = i+1
Comment on lines -11 to -17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11-17 refactored with the following changes:

This removes the following comments ( why? ):

# row value inside the loop

my_w.mainloop()
4 changes: 1 addition & 3 deletions Week-5/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def display():
window.geometry("400x250")

select = cursor.execute('''SELECT * from STFORM3 ''')
i = 0
for STFORM3 in select:
for i, STFORM3 in enumerate(select):
for j in range(len(STFORM3)):
e = Entry(my_w, width=10, fg='blue')
e.grid(row=i, column=j)
e.insert(END, STFORM3[j])
i = i+1
Comment on lines -56 to -62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function display refactored with the following changes:



an = Tk()
Expand Down
4 changes: 1 addition & 3 deletions Week-5/registration_form_with_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ def users_registered():
L17 = Label(window5,text="EMAIL").grid(row=0,column=5,pady=(60,0))
L17 = Label(window5,text="FULLNAME").grid(row=0,column=6,pady=(60,0))
cursor.execute("SELECT * FROM user_details")
i=1
for users in cursor:
for i, users in enumerate(cursor, start=1):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function users_registered refactored with the following changes:

for j in range(len(users)):
if(j==5):
j+=1
Expand All @@ -58,7 +57,6 @@ def users_registered():
E11 = Entry(window5, width=25, fg='black')
E11.grid(row=i, column=j)
E11.insert(END, users[j])
i=i+1
button_8 = Button(window5,text="QUIT",width=10,command=lambda: quit()).place(relx=0.5,rely=0.84,anchor=CENTER)


Expand Down
4 changes: 2 additions & 2 deletions Week-6/Mutliprogramming/Week06 Set08.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
def producer_func(name):
n = random.randint(10,20)
if obj._value+n <= MAX:
for i in range(n):
for _ in range(n):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function producer_func refactored with the following changes:

obj.release()
print(name, 'number of items: ', obj._value)
sleep(0.2)
Expand All @@ -28,7 +28,7 @@ def producer_func(name):
def consumer_func(name):
n = random.randint(1,20)
if obj._value+n >= 0:
for i in range(n):
for _ in range(n):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function consumer_func refactored with the following changes:

obj.acquire()
print(name, 'number of items: ', obj._value)
sleep(0.2)
Expand Down
2 changes: 1 addition & 1 deletion Week-6/Mutliprogramming/Week06 Set10.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def Writer():
print("Writer couldn't write, as Reading or Writing is taking place.")

if __name__ == '__main__':
for i in range(0, 10):
for _ in range(10):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 35-35 refactored with the following changes:

randomNumber = random.randint(0, 100)
if(randomNumber > 50):
threading1 = threading.Thread(target = Reader)
Expand Down
Loading