-
Notifications
You must be signed in to change notification settings - Fork 19
Sourcery Starbot ⭐ refactored ComputerScientist-01/Advanced-Programming-Practice #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print(sum) | ||
|
|
||
| n =input() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return dec_value; | ||
|
|
||
| if n == 1: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return num>=1 | ||
| pascal_triangle(n) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| m[b[i]] = val | ||
| else: | ||
| m[b[i]] = None | ||
|
|
||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| str = input("enter a sentence :\n ") | ||
| if ispangram(str): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,7 @@ def __init__(self): | |
| pass | ||
|
|
||
| def _getString(self): | ||
| s = input() | ||
| return s | ||
| return input() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def _printString(self,s): | ||
| print(s.upper()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = [] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for i in range (5): | ||
| self.marks.insert(i,int(input("enter %d th mark :"%(i+1)))) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'}: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| print ('Your BMI is %.1f'%BMI) | ||
|
|
||
| # Determine whether the user is underweight, overweight, or optimal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| monthchosen['values'] = ('Month:', | ||
| ' January', | ||
| ' February', | ||
|
|
@@ -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) | ||
|
|
@@ -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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| 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") | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| 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") | ||
|
|
||
|
|
@@ -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() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
This removes the following comments ( why? ): |
||
| my_w.mainloop() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| an = Tk() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| for j in range(len(users)): | ||
| if(j==5): | ||
| j+=1 | ||
|
|
@@ -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) | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| obj.release() | ||
| print(name, 'number of items: ', obj._value) | ||
| sleep(0.2) | ||
|
|
@@ -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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| obj.acquire() | ||
| print(name, 'number of items: ', obj._value) | ||
| sleep(0.2) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| randomNumber = random.randint(0, 100) | ||
| if(randomNumber > 50): | ||
| threading1 = threading.Thread(target = Reader) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
3-10refactored with the following changes:aug-assign)sum-comprehension)