Skip to content

Conversation

@sourcery-ai
Copy link

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main git merge --ff-only FETCH_HEAD git reset HEAD^ 

Help us improve this pull request!

Copy link
Author

@sourcery-aisourcery-aibot left a comment

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment on lines +4 to +7
ifwt[n-1]<=W:
returnmax(val[n-1]+knapsack_recursive(wt,val,W-wt[n-1],n-1),knapsack_recursive(wt,val,W,n-1))
else:
ifwt[n-1]<=W:
returnmax(val[n-1]+knapsack_recursive(wt,val,W-wt[n-1],n-1),knapsack_recursive(wt,val,W,n-1))
elifwt[n-1]>W:
returnknapsack_recursive(wt,val,W,n-1)
returnknapsack_recursive(wt,val,W,n-1)
Copy link
Author

Choose a reason for hiding this comment

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

Function knapsack_recursive refactored with the following changes:

foriinrange(4):
mat.append([0] *4)

mat= [[0] *4for_inrange(4)]
Copy link
Author

Choose a reason for hiding this comment

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

Function start_game refactored with the following changes:

This removes the following comments ( why? ):

# elements as 0. # appending 4 list each with four # declaring an empty list then 

Comment on lines -78 to +82
if(mat[i][j]==mat[i+1][j]ormat[i][j]==mat[i][j+1]):
ifmat[i][j]in [mat[i+1][j], mat[i][j+1]]:
return'GAME NOT OVER'

forjinrange(3):
if(mat[3][j]==mat[3][j+1]):
return'GAME NOT OVER'

foriinrange(3):
if(mat[i][3]==mat[i+1][3]):
return'GAME NOT OVER'

# else we have lost the game
return'LOST'
returnnext(
('GAME NOT OVER'foriinrange(3) if (mat[i][3] ==mat[i+1][3])),
'LOST',
)
Copy link
Author

Choose a reason for hiding this comment

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

Function get_current_state refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator (merge-comparisons)
  • Use the built-in function next instead of a for-loop (use-next)

This removes the following comments ( why? ):

# else we have lost the game 

Comment on lines -104 to +96
# empty grid
new_mat= []

# with all cells empty
foriinrange(4):
new_mat.append([0] *4)

new_mat= [[0] *4for_inrange(4)]
Copy link
Author

Choose a reason for hiding this comment

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

Function compress refactored with the following changes:

This removes the following comments ( why? ):

# empty grid # with all cells empty 

print("Please Press 3 To Pay in.")
print("Please Press 4 To Return Card.")

Copy link
Author

Choose a reason for hiding this comment

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

Lines 19-78 refactored with the following changes:

Comment on lines -8 to +18
fileHandle=open(fileName, "r")
withopen(fileName, "r") asfileHandle:
# Declare a variable to store the number of vowels. Initally it is zero.
count=0

# Declare a variable to store the number of vowels. Initally it is zero.
count=0
# create an array of all the vowels (upper and lower case) that can be used to compare and determine if a character is a vowel
vowels= ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']

# create an array of all the vowels (upper and lower case) that can be used to compare and determine if a character is a vowel
vowels= ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']

# Read each character and compare it to the characters in the array. If found in the vowels array, then increase count.
forcharinfileHandle.read():
ifcharinvowels:
count=count+1

# Close the file
fileHandle.close()
# Read each character and compare it to the characters in the array. If found in the vowels array, then increase count.
forcharinfileHandle.read():
ifcharinvowels:
count=count+1
Copy link
Author

Choose a reason for hiding this comment

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

Lines 8-22 refactored with the following changes:

This removes the following comments ( why? ):

# Close the file 

Comment on lines -26 to -30
ifmin_nodeisNone:
ifmin_nodeisNoneorvisited[node] <visited[min_node]:
min_node=node
elifvisited[node] <visited[min_node]:
min_node=node

Copy link
Author

Choose a reason for hiding this comment

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

Function dijsktra refactored with the following changes:

Comment on lines 4 to -6

list1=[]
list2=[]
Copy link
Author

Choose a reason for hiding this comment

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

Lines 4-32 refactored with the following changes:

This removes the following comments ( why? ):

# If Decimal Numbers occured in the Sentence 

forjinrange(3):

globals()[i+str(j+1)].configure(text=f' ')
globals()[i+str(j+1)].configure(text=' ')
Copy link
Author

Choose a reason for hiding this comment

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

Function Retry refactored with the following changes:

Comment on lines -86 to +88
ifXcount>Ocount:
string='Player 1(X) won'
else:
string='Player 2(O) won'
string='Player 1(X) won'ifXcount>Ocountelse'Player 2(O) won'
finish(string)

Copy link
Author

Choose a reason for hiding this comment

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

Function win_check refactored with the following changes:

Comment on lines -111 to +113
vars()[i+str(j+1)]=tk.Button(vars()[i], text=f' ',bd='1',command=partial(clicked,i+' '+str(j+1)))
vars()[i+str(j+1)] =tk.Button(
vars()[i],
text=' ',
bd='1',
command=partial(clicked, f'{i}{str(j+1)}'),
)
Copy link
Author

Choose a reason for hiding this comment

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

Lines 111-111 refactored with the following changes:



if(level!="hard"andlevel!="easy"):
iflevelnotin ["hard", "easy"]:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 24-24 refactored with the following changes:

Comment on lines -66 to +69
foriinrange(len(word)):
for_inrange(len(word)):
blank_list+="_"
end_game=False
whileend_game==False:
whilenotend_game:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 66-69 refactored with the following changes:

Comment on lines -5 to +11
hour=int(seconds/3600) #Gets hours
minute=int(seconds/60)-(hour*60) #Gets remanining minutes
hour=seconds//3600
minute=seconds//60-hour*60
second=seconds- (minute*60) - (hour*3600) #Gets remaining seconds

hour=str(hour) iflen(str(hour)) >1else'0'+str(hour)#adds 0 if the hours,minutes or seconds are only one charachter long
second=str(second) iflen(str(second)) >1else'0'+str(second)
minute=str(minute) iflen(str(minute)) >1else'0'+str(minute)
hour=str(hour) iflen(str(hour)) >1elsef'0{str(hour)}'
second=str(second) iflen(str(second)) >1elsef'0{str(second)}'
minute=str(minute) iflen(str(minute)) >1elsef'0{str(minute)}'
Copy link
Author

Choose a reason for hiding this comment

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

Function make_readable refactored with the following changes:

This removes the following comments ( why? ):

#adds 0 if the hours,minutes or seconds are only one charachter long #Gets remanining minutes #Gets hours 

Comment on lines -3 to +15

#screen for output
screen=turtle.Screen()

# Defining a turtle Instance
t=turtle.Turtle()
speed(0)

# initially penup()
t.penup()
t.goto(-400, 250)
t.pendown()

Copy link
Author

Choose a reason for hiding this comment

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

Lines 3-87 refactored with the following changes:

Comment on lines -31 to +41
foriinrange(0,nr_letters):
for_inrange(0,nr_letters):
random_letter=r.choice(letters)
random_letters.append(random_letter)

random_symbols= []
foriinrange(0,nr_symbols):
for_inrange(0,nr_symbols):
random_symbol=r.choice(symbols)
random_symbols.append(random_symbol)

random_numbers= []
foriinrange(0,nr_numbers):
for_inrange(0,nr_numbers):
Copy link
Author

Choose a reason for hiding this comment

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

Function hard_pass refactored with the following changes:

This removes the following comments ( why? ):

#e.g. 4 letter, 2 symbol, 2 number = g^2jk8&P #Hard Level - Order of characters randomised: 

val=None
whilenotvalid_square:
square=input(self.player+' turn. Please introduce a move (1-9): ')
square=input(f'{self.player} turn. Please introduce a move (1-9): ')
Copy link
Author

Choose a reason for hiding this comment

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

Function Human.get_move refactored with the following changes:

defget_move(self, game):
square=random.choice(game.remaining_moves())
returnsquare
returnrandom.choice(game.remaining_moves())
Copy link
Author

Choose a reason for hiding this comment

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

Function RandomComputer.get_move refactored with the following changes:

Comment on lines -46 to +49
iflen(game.remaining_moves()) ==9:
square=random.choice(game.remaining_moves())
else:
square=self.minimax(game, self.player)['position']
returnsquare
return (
random.choice(game.remaining_moves())
iflen(game.remaining_moves()) ==9
elseself.minimax(game, self.player)['position']
)
Copy link
Author

Choose a reason for hiding this comment

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

Function SmartComputer.get_move refactored with the following changes:

Comment on lines -78 to +83
ifplayer==max_player:
ifsim_score['score'] >best['score']:
best=sim_score
else:
ifsim_score['score'] <best['score']:
best=sim_score
if (
player==max_player
andsim_score['score'] >best['score']
orplayer!=max_player
andsim_score['score'] <best['score']
):
best=sim_score
Copy link
Author

Choose a reason for hiding this comment

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

Function SmartComputer.minimax refactored with the following changes:

Comment on lines -77 to +84

whileTrue:
window.update()

#moving the ball
ball.setx(ball.xcor()+ballxdirection)
ball.sety(ball.ycor()+ballxdirection)

Copy link
Author

Choose a reason for hiding this comment

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

Lines 77-117 refactored with the following changes:

This removes the following comments ( why? ):

# Handling the collisions with paddles. 

Comment on lines -7 to +11
iflen(self.arr) >0:
ditem=self.arr[0]
delself.arr[0]
returnditem
else:
iflen(self.arr) <=0:
return#queue is empty
ditem=self.arr[0]
delself.arr[0]
returnditem
Copy link
Author

Choose a reason for hiding this comment

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

Function Queue.dequeue refactored with the following changes:

t1= []
t2= []
while(len(y) !=0):
whiley:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 5-5 refactored with the following changes:

randomInteger=random.randint(0,2)
userInput=int(input("What do you choose ? Type 0 for Rock,1 for Paper or 2 for Scissors\n"))
if(userInput!=0anduserInput!=1anduserInput!=2):
ifuserInputnotin [0, 1, 2]:
Copy link
Author

Choose a reason for hiding this comment

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

Lines 5-5 refactored with the following changes:

Comment on lines -100 to +119

#hiding segments of snake
forsegmentinsegments:
segment.goto(1000,1000)
#clearing the segments
segments.clear()

#reset score
score=0

#reset delay
delay=0.1

pen.clear()
pen.write("Score :{} High Score :{} ".format(
score, high_score), align="center", font=("Times New Roman", 24, "bold"))

pen.write(
f"Score : {score} High Score : {high_score} ",
align="center",
font=("Times New Roman", 24, "bold"),
)

Copy link
Author

Choose a reason for hiding this comment

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

Lines 100-175 refactored with the following changes:

Comment on lines -48 to +52
print(f"Current Balance : ${self.balance}")
print()
else:
print("Not Enough Balance!!!")
print(f"Current Balance : ${self.balance}")
print()
print("Not Enough Balance!!!")

print(f"Current Balance : ${self.balance}")
print()
Copy link
Author

Choose a reason for hiding this comment

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

Function Bank.withdraw refactored with the following changes:

n=int(input("Enter number of elements: "))
print("Enter the elements")
foriinrange(0,n):
for_inrange(0,n):
Copy link
Author

Choose a reason for hiding this comment

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

Function userInput refactored with the following changes:

forcharinname:
ifchar.isupper():
print("_"+char.lower(), end="")
print(f"_{char.lower()}", end="")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 7-7 refactored with the following changes:

Comment on lines -9 to +12
print(f'Initial number is: {initial_number}')
print(f'Initial number is: {num}')
whilenum!=1:
print(num)
ifnum%2==0:
num=int(num/2)
else:
num=int(3*num+1)
num=int(num/2) ifnum%2==0elseint(3*num+1)
Copy link
Author

Choose a reason for hiding this comment

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

Function collatz refactored with the following changes:

Comment on lines -7 to +11
maxNum=1000; #maximum number in array
lengthOfItems=500; #this will generate 500 random numbers.

file=open("newFile.csv", "a") # creates a new file named newFile.csv - feel free to edit file name

foriinrange(lengthOfItems):
file.write(str(str(rd.randint(minNum,maxNum)) +","))

file.close()
maxNum=1000
lengthOfItems=500
withopen("newFile.csv", "a") asfile:
for_inrange(lengthOfItems):
file.write(str(f"{str(rd.randint(minNum, maxNum))},"))
Copy link
Author

Choose a reason for hiding this comment

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

Lines 7-15 refactored with the following changes:

This removes the following comments ( why? ):

# creates a new file named newFile.csv - feel free to edit file name #this will generate 500 random numbers. #maximum number in array 

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant