-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -10,13 +10,7 @@ | |
| # at the start | ||
| def start_game(): | ||
|
|
||
| # declaring an empty list then | ||
| # appending 4 list each with four | ||
| # elements as 0. | ||
| mat =[] | ||
| for i in range(4): | ||
| mat.append([0] * 4) | ||
|
|
||
| mat = [[0] * 4 for _ in range(4)] | ||
|
Author
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
This removes the following comments ( why? ): |
||
| # printing controls for user | ||
| print("Commands are as follows : ") | ||
| print("'W' or 'w' : Move Up") | ||
|
|
@@ -75,19 +69,17 @@ def get_current_state(mat): | |
| # cell then also game is not yet over | ||
| for i in range(3): | ||
| for j in range(3): | ||
| if(mat[i][j]== mat[i + 1][j] or mat[i][j]== mat[i][j + 1]): | ||
| if mat[i][j] in [mat[i + 1][j], mat[i][j + 1]]: | ||
| return 'GAME NOT OVER' | ||
|
|
||
| for j in range(3): | ||
| if(mat[3][j]== mat[3][j + 1]): | ||
| return 'GAME NOT OVER' | ||
|
|
||
| for i in range(3): | ||
| if(mat[i][3]== mat[i + 1][3]): | ||
| return 'GAME NOT OVER' | ||
|
|
||
| # else we have lost the game | ||
| return 'LOST' | ||
| return next( | ||
| ('GAME NOT OVER' for i in range(3) if (mat[i][3] == mat[i + 1][3])), | ||
| 'LOST', | ||
| ) | ||
|
Comment on lines
-78
to
+82
Author
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
This removes the following comments ( why? ): |
||
|
|
||
| # all the functions defined below | ||
| # are for left swap initially. | ||
|
|
@@ -101,13 +93,7 @@ def compress(mat): | |
| # any change happened or not | ||
| changed = False | ||
|
|
||
| # empty grid | ||
| new_mat = [] | ||
|
|
||
| # with all cells empty | ||
| for i in range(4): | ||
| new_mat.append([0] * 4) | ||
|
|
||
| new_mat = [[0] * 4 for _ in range(4)] | ||
|
Comment on lines
-104
to
+96
Author
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
This removes the following comments ( why? ): |
||
| # here we will shift entries | ||
| # of each cell to it's extreme | ||
| # left row by row | ||
|
|
@@ -119,13 +105,13 @@ def compress(mat): | |
| # in respective row | ||
| for j in range(4): | ||
| if(mat[i][j] != 0): | ||
|
|
||
| # if cell is non empty then | ||
| # we will shift it's number to | ||
| # previous empty cell in that row | ||
| # denoted by pos variable | ||
| new_mat[i][pos] = mat[i][j] | ||
|
|
||
| if(j != pos): | ||
| changed = True | ||
| pos += 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| print("Please Press 2 To Make a Withdrawl.") | ||
| print("Please Press 3 To Pay in.") | ||
| print("Please Press 4 To Return Card.") | ||
|
|
||
|
Author
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. 1CF5Lines
|
||
| option = int(input("\nWhat Would you like to Choose?: ")) | ||
|
|
||
| if option == 1: | ||
|
|
@@ -31,7 +31,7 @@ | |
| option2 = ("y") | ||
| withdrawl = float(input("\nHow Much Would you like to withdraw? 10, 20, 40, 60, 80, 100 for other enter 1: ")) | ||
|
|
||
| if withdrawl in [10, 20, 40, 60, 80, 100]: | ||
| if withdrawl in {10, 20, 40, 60, 80, 100}: | ||
| balance = balance - withdrawl | ||
| print(f"\nYour balance after the withdrawl is ${balance}") | ||
| restart = input("\nWould You like to do something else? ") | ||
|
|
@@ -73,9 +73,9 @@ | |
| print("\nPlease enter a correct number.\n") | ||
| restart = ("y") | ||
|
|
||
| elif pin != (1234): | ||
| else: | ||
| print("\nINCORRECT PIN!!\n") | ||
| chances = chances - 1 | ||
| chances -= 1 | ||
|
|
||
| if chances == 0: | ||
| print("Calling the Police...\n") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ def main(): | |
| age = calculate_age(datetime.date(year, month, day)) | ||
|
|
||
| # Print the age | ||
| print("Your age is: {}".format(age)) | ||
| print(f"Your age is: {age}") | ||
|
Author
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
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,21 +3,17 @@ | |
| import math | ||
|
|
||
| def square(side): | ||
| area = side * side | ||
| return area | ||
| return side * side | ||
|
Author
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 rectangle(length, breadth): | ||
| area = length * breadth | ||
| return area | ||
| return length * breadth | ||
|
Comment on lines
-10
to
+9
Author
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 triangle(side1, side2, side3): | ||
| s = (side1 + side2 + side3)/2 | ||
| area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3)) | ||
| return area | ||
| return math.sqrt(s*(s-side1)*(s-side2)*(s-side3)) | ||
|
Comment on lines
-15
to
+13
Author
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 circle(radius): | ||
| area = 3.14 * radius * radius | ||
| return area | ||
| return 3.14 * radius * radius | ||
|
Comment on lines
-19
to
+16
Author
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
|
||
|
|
||
| final_area = 0.0 | ||
| print("Choose the shape you want to calculate area of: ") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,5 @@ | ||
| print("An Armstrong Number is a number which is equal to the sum of the cubes of it's digits.") | ||
| inputNumber = input("Enter a number to check if it's an Armstrong Number or not: ") | ||
| sumOfCubes=0 | ||
|
|
||
| for digit in inputNumber: | ||
| sumOfCubes+=int(digit)**3 | ||
|
|
||
| sumOfCubes = sum(int(digit)**3 for digit in inputNumber) | ||
|
Author
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
|
||
| if sumOfCubes==int(inputNumber): print(inputNumber,"is an Armstrong Number.") | ||
| else: print(inputNumber,"is NOT an Armstrong Number.") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| n=int(input("Enter the number of elements to be inserted: ")) | ||
| a=[] | ||
| for i in range(0,n): | ||
| for _ in range(0,n): | ||
|
Author
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
|
||
| elem=int(input("Enter element: ")) | ||
| a.append(elem) | ||
| avg=sum(a)/n | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,14 +2,14 @@ | |
| import random | ||
| class BankGame : | ||
| @staticmethod | ||
| def main( args) : | ||
| def main( args): | ||
| print("---WELCOME TO ELIX BANKING SERVICES---") | ||
| print("") | ||
| print("________________________") | ||
| print("Enter your name: ") | ||
| name = input() | ||
| # I am inserting do loop to make the program run forever under correct inputs. | ||
| print("Hi, " + name + "\bWelcome to my program!") | ||
| print(f"Hi, {name}" + "\bWelcome to my program!") | ||
|
Comment on lines
-5
to
+12
Author
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
This removes the following comments ( why? ): |
||
| print("____________________________") | ||
| print("Do you want to start/repeat the program?") | ||
| print("Enter Y for Yes and N for No: ") | ||
|
|
@@ -20,14 +20,12 @@ def main( args) : | |
| print("If you don\'t know the password refer the first line of the program") | ||
| print("Please enter the password: ") | ||
| # Condition when the statement goes true i.e.- temp equals 1 | ||
| while True : | ||
| if (temp == 'Y' or temp == 'y') : | ||
| if (passw == 4758) : | ||
| while True: | ||
| if temp in ['Y', 'y']: | ||
| if (passw == 4758): | ||
| print("") | ||
| print("Your initial account balance is Rs. 10000") | ||
| # Using for statement to perform 5 operation on each login | ||
| x = 0 | ||
| while (x <= 6) : | ||
| for _ in range(7): | ||
| print("0. Exit") | ||
| print("1. Deposit") | ||
| print("2. Withdraw") | ||
|
|
@@ -41,57 +39,56 @@ def main( args) : | |
| print(captha) | ||
| print("Enter the number shown above: ") | ||
| verify = int(input()) | ||
| if (verify == captha) : | ||
| if (verify == captha): | ||
| # If captha gets matched, then these switch statements are executed. | ||
| if (choice==0): | ||
| print("BYE!......" + name + " HAVE A NICE DAY!") | ||
| if choice == 0: | ||
| print(f"BYE!......{name} HAVE A NICE DAY!") | ||
| print("__________________________") | ||
| print("@author>[@programmer-yash") | ||
| print("Please comment here or open an issue if you have any queries or suggestions!") | ||
| print("") | ||
| print("#hacktoberfest") | ||
| return 0 | ||
| elif(choice==1): | ||
| elif choice == 1: | ||
| print("You have chosen to deposit.") | ||
| print("Enter the amount to deposit : ") | ||
| deposit = int(input()) | ||
| bal = bal + deposit | ||
| print(str(deposit) + " has been deposited to your account.") | ||
| print("Left balance is " + str(bal)) | ||
| elif(choice==2): | ||
| print(f"{deposit} has been deposited to your account.") | ||
| print(f"Left balance is {str(bal)}") | ||
| elif choice == 2: | ||
| print("You have chosen to withdraw.") | ||
| print("Enter the amount to be withdrawn") | ||
| withdraw = int(input()) | ||
| print(str(+withdraw) + " has been withdrawn from your account.") | ||
| print(f"{str(+withdraw)} has been withdrawn from your account.") | ||
| 2323 bal = bal - withdraw | ||
| print("Check the cash printer.") | ||
| print("Left balance is " + str(bal)) | ||
| elif(choice==3): | ||
| print(f"Left balance is {str(bal)}") | ||
| elif choice == 3: | ||
| print("You have chosen to change passcode.") | ||
| print("Enter the current passcode: ") | ||
| check = int(input()) | ||
| if (check == passw) : | ||
| if (check == passw): | ||
| print("Enter the new passcode") | ||
| newP = int(input()) | ||
| passw = newP | ||
| print("Your new password is " + str(newP)) | ||
| else : | ||
| print(f"Your new password is {passw}") | ||
| else: | ||
| print("Wrong passcode!") | ||
| elif(choice==4): | ||
| elif choice == 4: | ||
| print("You have chosen to check balanace.") | ||
| print("Your current account balance is " + str(bal)) | ||
| elif(choice==5): | ||
| print(f"Your current account balance is {str(bal)}") | ||
| elif choice == 5: | ||
| print("You have chosen for customer care.") | ||
| print("Contact us at:") | ||
| print(" Email: yash197911@gmail.com") | ||
| else: | ||
| print("Wrong choice!!! Choose again...!") | ||
| else : | ||
| else: | ||
| print("xCAPTHA NOT CORRECTx") | ||
| x += 1 | ||
| continue | ||
| elif(temp == 'N' or temp == 'n') : | ||
| print("BYE!......" + name + " HAVE A NICE DAY!") | ||
| elif temp in ['N', 'n']: | ||
| print(f"BYE!......{name} HAVE A NICE DAY!") | ||
| print("__________________________") | ||
| print("@author>[@programmer-offbeat]") | ||
| print("Please comment here if you have any queries or suggestions!") | ||
|
|
@@ -101,14 +98,14 @@ def main( args) : | |
| print() | ||
| print("HAPPY CODING!:-)") | ||
| return 0 | ||
| else : | ||
| else: | ||
| print("Err!..... You have entered a wrong choice!") | ||
| print("Try again....!") | ||
| # Comdition if password mismatches. | ||
| if (passw != 4758) : | ||
| print("You have entered wrong password.....Try again!") | ||
| if((temp < 100) == False) : | ||
| break | ||
| if temp >= 100: | ||
| break | ||
|
|
||
|
|
||
| if __name__=="__main__": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,14 +47,14 @@ def bif(x0, r): | |
| if __name__ == '__main__': | ||
| # create and configure the process pool | ||
| with Pool(4) as p: | ||
|
|
||
| for i,ch in enumerate(p.map(bif1,r,chunksize=2500)) : | ||
| x1=np.ones(len(ch))*r[i] | ||
| X.append(x1) | ||
| Y.append(ch) | ||
| print("--- %s seconds ---" % (time.time() - start_time)) | ||
| print(f"--- {time.time() - start_time} seconds ---") | ||
|
|
||
| plt.style.use('dark_background') | ||
| plt.style.use('dark_background') | ||
|
Comment on lines
-50
to
+57
Author
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
|
||
| plt.plot(X,Y, ".w", alpha=1, ms=1.2) | ||
| figure = plt.gcf() # get current figure | ||
| figure.set_size_inches(1920 / 40, 1080 / 40) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,25 +13,18 @@ | |
| print(logo) | ||
| cards=[11,2,3,4,5,6,7,8,9,10,10,10,10] | ||
|
|
||
| player=[] | ||
| computer=[] | ||
|
|
||
| player_sum=0 | ||
| computer_sum=0 | ||
|
|
||
| player.append(random.choice(cards)) | ||
|
|
||
|
|
||
| player = [random.choice(cards)] | ||
|
Comment on lines
-16
to
+19
Author
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
|
||
| rand = random.choice(cards) | ||
| if (rand == 11 and rand + computer_sum > 21): | ||
| player.append(1) | ||
| else: | ||
| player.append(rand) | ||
|
|
||
|
|
||
| computer.append(random.choice(cards)) | ||
|
|
||
|
|
||
| computer = [random.choice(cards)] | ||
| randco = random.choice(cards) | ||
| if (rand == 11 and rand + computer_sum > 21): | ||
| computer.append(1) | ||
|
|
@@ -41,21 +34,21 @@ | |
| player_sum+=player[0]+player[1] | ||
| computer_sum+=computer[0]+computer[1] | ||
|
|
||
| while(player_sum<=21): | ||
| while (player_sum<=21): | ||
| print(f"Your cards : {player} ,current score : {player_sum}") | ||
| print(f"Computer's first card : {computer[0]}") | ||
|
|
||
| accept=input("Type y to get another card , Type n to pass : ") | ||
| if(accept=='y'): | ||
| rand=random.choice(cards) | ||
| if(rand==11 and rand+player_sum>21): | ||
| player_sum+=1 | ||
| player.append(1) | ||
| else: | ||
| player_sum+=rand | ||
| player.append(rand) | ||
| else:break | ||
| if accept != 'y': | ||
| break | ||
|
|
||
| rand=random.choice(cards) | ||
| if(rand==11 and rand+player_sum>21): | ||
| player_sum+=1 | ||
| player.append(1) | ||
| else: | ||
| player_sum+=rand | ||
| player.append(rand) | ||
| if player_sum>21: | ||
| print(f"Your cards : {player} ,current score : {player_sum}") | ||
| print("You Lost") | ||
|
|
||
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.
Function
knapsack_recursiverefactored with the following changes:remove-unnecessary-else)remove-redundant-if)