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
28 changes: 28 additions & 0 deletions Test2/P01_hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Author: OMKAR PATHAK
# This program prints the entered message

def justPrint(text):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Misleading or Vague Function Name

The function name 'justPrint' uses camelCase, which violates Python's snake_case convention. Additionally, the name is vague and doesn't reflect that the function also performs arithmetic and user input operations.

Suggested change
def justPrint(text):
def print_and_calculate_values(text):
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require function names to be in snake_case
  2. The name 'justPrint' is misleading as the function body contains complex logic beyond printing
  3. Descriptive names like 'print_and_calculate_values' improve code maintainability

Gaps

  1. The function's primary intent seems to be a demonstration script rather than a production utility
  2. 'justPrint' might be a legacy name from a developer transitioning from Java/JS

'''This function prints the text passed as argument to this function'''
print(text)
first_number = input("Enter a number: ")
second_number = input("Enter another number: ")
base_value = 10
increment_value=20
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 100% View Citation

JAS - Just a suggestion
Missing Whitespace Around Operator

According to PEP 8, there should be a single space around the assignment operator to improve readability.

Suggested change
increment_value=20
increment_value = 20

difference = increment_value - base_value
divide_value = increment_value / base_value
multiply_value = increment_value * base_value
floor_division = increment_value // base_value # // -> integer division

print("Floor Division:", floor_division)
# print("Difference is:", increment_value - base_value)
print("Divide value is:", divide_value)
print("Multiply value is:", multiply_value)
print("Modulus:", increment_value % base_value ) # % -> remainder
print('Addition is:', int(a) + int(b))
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical Confidence Score: 100%

Undefined Variable Reference

I noticed that we're trying to use variables a and b in the addition logic, but they haven't been defined anywhere in the function or global scope. This will cause a NameError as soon as the code reaches this line. We should use the variables first_number and second_number that were collected from the user input earlier.

Suggested change
print('Addition is:', int(a) + int(b))
print('Addition is:', int(first_number) + int(second_number))


if __name__ == '__main__':
justPrint('Hello Sindhuja')
justPrint('Hello Sindhuja')
justPrint('Hello Sindhuja')


17 changes: 17 additions & 0 deletions Test2/P04_Factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Author: OMKAR PATHAK
#This program finds the favtorial of the specified numbers
#For example, factorial of 5 = 5*4*3*2*1 = 120

def factorial(number):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Forbidden Generic Parameter Name

The parameter name 'number' is explicitly listed as a forbidden generic name. Using a more descriptive name like 'input_value' or 'n' (if following mathematical conventions) is preferred.

Suggested change
def factorial(number):
def factorial(n):
Reasons & Gaps

Reasons

  1. The name 'number' is explicitly identified as a forbidden generic name in the coding standard
  2. Generic names reduce semantic clarity regarding the specific type or role of the input
  3. Using 'n' aligns with standard mathematical notation for factorial operations

Gaps

  1. In mathematical contexts, 'number' is often considered a descriptive domain term despite being on the forbidden list
  2. The function name 'factorial' provides significant context that may mitigate the generic nature of the parameter

'''This function finds the factorial of the number passed as argument'''
if number < 0:
print('Invalid entry! Cannot find factorial of a negative number')
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical Confidence Score: 100%

Infinite Recursion on Negative Input

I noticed that when a negative number is entered, the function prints an error message but continues execution. Since it doesn't return early, it proceeds to the recursive call, leading to a RecursionError (stack overflow). We should return None or raise an exception immediately after detecting a negative input.

Suggested change
print('Invalid entry! Cannot find factorial of a negative number')
return None

if number == 0 or number == 1:
print("Hello")
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 100%

JAS - Just a suggestion
Residual Debug Print

It looks like there's a "Hello" print statement left in the base case logic. This appears to be debugging code that might clutter the output for the end user. We should remove it to keep the function's output clean and focused on the result.

return 1
else:
return number * factorial(number - 1)

if __name__ == '__main__':
userInput = int(input('Enter the Number to find the factorial of: '))
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Incorrect Variable Naming Convention

In Python, variable names should follow the snake_case convention. The current name userInput uses camelCase, which is inconsistent with PEP 8 standards.

Suggested change
userInput = int(input('Enter the Number to find the factorial of: '))
user_input = int(input('Enter the Number to find the factorial of: '))
Reasons & Gaps

Reasons

  1. Python's PEP 8 style guide mandates the use of snake_case for variable and function names
  2. Consistent casing improves code maintainability and follows community-wide expectations
  3. Mixed casing styles within a Python project can lead to confusion and reduced readability

Gaps

  1. Some projects may adopt camelCase for consistency with legacy code or specific internal guidelines
  2. The variable name itself is descriptive, only the casing style is technically a violation

print(factorial(userInput))
112 changes: 112 additions & 0 deletions Test2/P05_Pattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#Author: OMKAR PATHAK
#This program prints various patterns

def pattern1(level):
'''This function prints the following pattern:

*
**
***
****

'''
for i in range(1, level + 1):
print()
for j in range(i):
print('*', end = '')

def pattern2(level):
'''This function prints the following pattern:

****
***
**
*

'''
for i in range(level, 0, -1):
print()
for j in range(i):
print('*', end = '')

def pattern3(level):
'''This function prints the following pattern:

*
**
***
****

'''
counter = level
for i in range(level + 1):
print(' ' * counter + '*' * i)
counter -= 1

def pattern4(level):
'''This function prints the following pattern:

****
***
**
*

'''
counter = 0
for i in range(level, 0 ,-1):
print(' ' * counter + '*' * i)
counter += 1

def pattern5(level):
'''This function prints the following pattern:

*
***
*****

'''
# first loop for number of lines
for i in range(level + 1):
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Redundant Empty Line in Pattern 5

I noticed that pattern5 prints an extra empty line at the start. This happens because the loop starts at i=0, resulting in range(-1) for stars. We should start the range from 1 to match the intended pattern.

Suggested change
for i in range(level + 1):
for i in range(1, level + 1):

#second loop for spaces
for j in range(level - i):
print (" ",end='')
# this loop is for printing stars
for k in range(2 * i - 1):
print("*", end='')
print()


if __name__ == '__main__':
userInput = int(input('Enter the level: '))
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Non-Standard Variable Naming Convention

The variable userInput uses camelCase, which is inconsistent with Python's snake_case convention. Renaming it to user_input improves consistency with PEP 8 standards.

Suggested change
userInput = int(input('Enter the level: '))
user_input = int(input('Enter the level: '))
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) recommend snake_case for variable names
  2. Consistent casing across the codebase reduces cognitive load for developers
  3. Improves alignment with standard Python library naming patterns

Gaps

  1. The variable is functional and descriptive, making this a stylistic refinement rather than a logic error
  2. Project-specific naming conventions might occasionally permit camelCase in specific modules

pattern1(userInput)
print()
pattern2(userInput)
print()
pattern3(userInput)
print()
pattern4(userInput)
print()
pattern5(userInput)
print()

def pattern6(userInput):
'''
following is the another approach to solve pattern problems with reduced time complexity

for

*
**
***
****
*****
'''

num = userInput
pattern = '*'
string = pattern * num
x = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Single-Character Variable Name

The variable name x is non-descriptive. In the context of this loop, it acts as a counter or index for string slicing. A name like current_index or char_count would be more meaningful.

Suggested change
x = 0
char_count = 0
Reasons & Gaps

Reasons

  1. Single-character names (except loop counters) fail to convey the variable's purpose
  2. Using 'char_count' explicitly describes that the variable tracks the number of characters to print
  3. Descriptive names make the logic of string slicing (string[0:x]) easier to follow

Gaps

  1. Single-letter variables like 'x' are sometimes used in mathematical or coordinate contexts
  2. The local scope of the function limits the impact of the vague naming


for i in string:
x = x + 1
print(string[0:x])
Comment on lines +92 to +112
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Nested Function Definition in Main Block

It looks like pattern6 is defined inside the if __name__ == '__main__': block. This makes the function inaccessible if the module is imported elsewhere. Let's move the definition to the top level with the other functions.

18 changes: 18 additions & 0 deletions Test2/P06_CharCount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Author: OMKAR PATHAK
#This program checks for the character frequency in the given string

def charFrequency(userInput):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Function Naming Convention (Case Style)

In Python, function names should follow the snake_case convention rather than camelCase. Renaming this to get_char_frequency would align with PEP 8 standards.

Suggested change
def charFrequency(userInput):
def get_char_frequency(user_input):
Reasons & Gaps

Reasons

  1. PEP 8 explicitly recommends snake_case for function and variable names in Python
  2. Consistent naming styles improve code maintainability and developer onboarding
  3. Standardized naming helps distinguish functions from classes (PascalCase) at a glance

Gaps

  1. The project might be following a legacy camelCase convention not visible in this diff
  2. Some teams prefer camelCase for consistency with other languages in a polyglot stack

Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 88% View Citation

JAS - Just a suggestion
Variable Naming (Refinement)

The parameter userInput uses camelCase. In Python, user_input is the preferred idiomatic style for variable names.

Suggested change
def charFrequency(userInput):
def get_char_frequency(user_input):
Reasons & Gaps

Reasons

  1. Aligning with snake_case improves consistency across the Python ecosystem
  2. Refined naming reduces cognitive friction for developers accustomed to PEP 8
  3. Consistent casing prevents mixed-style variables like 'user_input' and 'userInput'

Gaps

  1. The term 'userInput' is descriptive enough to be understood without confusion
  2. Naming style preferences can vary between specific team internal guidelines

'''This fuction helps to count the char frequency in the given string '''
userInput = userInput.lower() #covert to lowercase
dict = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 92% View Citation

JAS - Just a suggestion
Variable Naming (Built-in Shadowing)

The variable name dict shadows the built-in Python dict type. This can lead to subtle bugs and is considered a forbidden generic name in this context.

Suggested change
dict = {}
char_counts = {}
Reasons & Gaps

Reasons

  1. Shadowing built-ins prevents access to the original constructor within the local scope
  2. 'dict' is a generic type name that doesn't describe the data being stored
  3. 'char_counts' explicitly communicates that the variable stores frequency data

Gaps

  1. Local scope limits the impact of shadowing to this specific function
  2. The code is functional despite the shadowing, making it a low-risk readability issue

for char in userInput:
keys = dict.keys()
if char in keys:
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 100%

JAS - Just a suggestion
Inefficient Dictionary Key Lookup

I noticed we're calling dict.keys() inside the loop. In Python, checking if char in dict is more direct and efficient than creating a view of keys first. This simplifies the logic and improves performance for longer strings.

Suggested change
if char in keys:
if char in dict:

dict[char] += 1
else:
dict[char] = 1
return dict

if __name__ == '__main__':
userInput = str(input('Enter a string: '))
print(charFrequency(userInput))
23 changes: 23 additions & 0 deletions Test2/P07_PrimeNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Author: OMKAR PATHAK
#This program checks whether the entered number is prime or not

def checkPrime(number):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Boolean-Returning Function Without Prefix

The function returns boolean values (via isPrime) but lacks a standard boolean prefix like is_ or has_. In Python, is_prime is more idiomatic and clearly indicates a boolean return type.

Suggested change
def checkPrime(number):
def is_prime(number):
Reasons & Gaps

Reasons

  1. Function names returning booleans should start with is, has, or can
  2. Improves code predictability by signaling the expected return type
  3. Follows Python PEP 8 naming conventions for boolean-like functions

Gaps

  1. The function currently prints results instead of just returning a boolean
  2. Renaming might require updating all call sites which are visible in this diff

'''This function checks for prime number'''
isPrime = False
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Variable Naming Convention (Case Style)

The variable isPrime uses camelCase, which is not the standard convention for Python variables. Python variables should use snake_case (e.g., is_prime) to maintain consistency with the language style guide.

Suggested change
isPrime = False
is_prime = False
Reasons & Gaps

Reasons

  1. PEP 8 recommends snake_case for all variable and function names
  2. Consistent casing reduces cognitive load when reading Python code
  3. Avoids mixing naming styles within a single Python module

Gaps

  1. Project-specific style guides might occasionally allow camelCase for consistency
  2. The logic remains functional regardless of the naming casing used

if number == 2:
print(number, 'is a Prime Number')
if number > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Redundant Output for Number 2

I noticed that when the input is 2, the program prints that it is a prime number twice. This happens because both the specific check for 2 and the general loop logic (which doesn't execute for 2 but triggers the isPrime check) are active. We can fix this by using an elif to ensure only one block executes.

Suggested change
if number > 1:
elif number > 1:

for i in range(2, number):
if number % i == 0:
print(number, 'is not a Prime Number')
isPrime = False
break
else:
isPrime = True

if isPrime:
print(number, 'is a Prime Number')

if __name__ == '__main__':
userInput = int(input('Enter a number to check: '))
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Variable Naming Convention (Case Style)

The variable userInput uses camelCase. In Python, the standard naming convention for variables is snake_case. Renaming this to user_input would align with PEP 8 recommendations.

Suggested change
userInput = int(input('Enter a number to check: '))
user_input = int(input('Enter a number to check: '))
Reasons & Gaps

Reasons

  1. Pythonic code uses underscores to separate words in variable names
  2. Improves readability by following the ecosystem's established patterns
  3. Ensures the codebase looks professional and follows language best practices

Gaps

  1. The variable name is descriptive, only the casing style is non-standard
  2. Local script context often sees relaxed naming, though standards still apply

checkPrime(userInput)
13 changes: 13 additions & 0 deletions Test2/P20_OsModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Author: OMKAR PATHAK
#This program illustrates the example for os module in short

import os
import time

print(os.getcwd()) #Prints the current working directory

os.mkdir('newDir1')
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Potential FileExistsError

I notice we're calling os.mkdir('newDir1') without checking if the directory already exists. If this script is run a second time, it will crash with a FileExistsError. We should add a check or use exist_ok=True to make this more robust.

Suggested change
os.mkdir('newDir1')
if not os.path.exists('newDir1'):
os.mkdir('newDir1')

for i in range(1,10):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 72% View Citation

JAS - Just a suggestion
Single-Character Loop Variable

While 'i' is common for loop counters, using a more descriptive name like 'directory_index' or 'folder_number' can improve readability in scripts performing file system operations.

Suggested change
for i in range(1,10):
for directory_index in range(1, 10):
Reasons & Gaps

Reasons

  1. Descriptive names clarify the purpose of the loop variable within the logic
  2. Improves maintainability when the loop body involves complex string manipulations
  3. Helps distinguish between multiple nested loops if the script expands in the future

Gaps

  1. Standard 'i' is explicitly exempted for loop counters in the provided coding standard rules
  2. The script is a short illustration where 'i' is contextually understood as an index

print('Here i is',i)
os.rename('newDir' + str(i),'newDir' + str(i + 1))
time.sleep(2)
24 changes: 24 additions & 0 deletions Test2/P21_GuessTheNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Author: OMKAR PATHAK
#This program guesses the randomnly generated number


import random

def guess():
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Vague Verb in Function Name

The function name guess consists of a single generic verb. Adding a noun, such as play_guessing_game, makes the function's purpose clearer.

Suggested change
def guess():
def play_guessing_game():
Reasons & Gaps

Reasons

  1. Generic verbs without nouns fail to describe the specific action target
  2. 'play_guessing_game' explicitly communicates the function's role in the application
  3. Descriptive names act as internal documentation for future code maintenance

Gaps

  1. In a small script, a short name like 'guess' might be considered contextually sufficient
  2. The function is the primary logic of the script, making its purpose somewhat obvious

''' This function guesses the randomnly generated number '''
randomNumber = random.randint(0, 21)
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Off-by-One Error in Random Range

I noticed that the random number is generated between 0 and 21, but the user prompt suggests the range is 0 to 20. This means a user could never guess the number 21 if it's generated, leading to a frustrating experience. We should align the generation range with the user instructions.

Suggested change
randomNumber = random.randint(0, 21)
randomNumber = random.randint(0, 20)

Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Variable Naming Convention (camelCase)

In Python, variable names should follow the snake_case convention rather than camelCase. Renaming randomNumber to random_number aligns with PEP 8 standards.

Suggested change
randomNumber = random.randint(0, 21)
random_number = random.randint(0, 21)
Reasons & Gaps

Reasons

  1. Python's PEP 8 style guide explicitly recommends snake_case for variable names
  2. Consistent casing improves code maintainability and follows community standards
  3. camelCase is typically reserved for class names or other languages like Java/JS

Gaps

  1. Project-specific style guides sometimes allow camelCase for consistency with legacy code
  2. The variable name is descriptive despite the casing convention violation

count = 0

while True:
count += 1
number = int(input('Enter the number between 0 to 20: '))
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Potential Runtime Crash on Invalid Input

Currently, if a user enters something that isn't a number (like a letter or a blank space), the program will crash with a ValueError. It's a good practice to wrap the input conversion in a try-except block to handle these cases gracefully and keep the game running.

Suggested change
number = int(input('Enter the number between 0 to 20: '))
try:
number = int(input('Enter the number between 0 to 20: '))
except ValueError:
print('Please enter a valid integer.')
continue

if number < randomNumber:
print('Too small')
elif number > randomNumber:
print('Too large')
else:
print('You have got it in', count, 'tries')
break

if __name__ == '__main__':
guess()
23 changes: 23 additions & 0 deletions Test2/P22_SequentialSearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#Author: OMKAR PATHAK
#This program is an example for sequential search

def sequentialSearch(target, List):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Type Prefix in Variable Name

The parameter name 'List' uses a type indicator as a name, which is a form of Hungarian notation. In Python, it is also a built-in type name. Use a descriptive name like 'items' or 'search_list' instead.

Suggested change
def sequentialSearch(target, List):
def sequentialSearch(target, items):
Reasons & Gaps

Reasons

  1. Using 'List' as a variable name shadows the built-in Python list type
  2. Hungarian notation (type prefixes) is discouraged in modern Python development
  3. Descriptive names like 'items' improve clarity regarding the variable's purpose

Gaps

  1. 'List' is a built-in type in Python, making its use as a variable name technically valid but highly discouraged
  2. The context clearly implies a collection, but project-specific naming conventions are unknown

'''This function returns the position of the target if found else returns -1'''
position = 0
global iterations
iterations = 0
while position < len(List):
iterations += 1
if target == List[position]:
return position
position += 1
return -1
Comment on lines +4 to +14
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 100%

Global State for Iteration Counting

Using a global variable iterations to track search progress makes the function non-thread-safe and prone to errors if called multiple times without manual resets. It's better to return the count alongside the result or encapsulate it within a class to maintain state properly.

Suggested change
def sequentialSearch(target, List):
'''This function returns the position of the target if found else returns -1'''
position = 0
global iterations
iterations = 0
while position < len(List):
iterations += 1
if target == List[position]:
return position
position += 1
return -1
def sequentialSearch(target, List):
'''This function returns the position and iterations of the target if found else returns -1, iterations'''
position = 0
iterations = 0
while position < len(List):
iterations += 1
if target == List[position]:
return position, iterations
position += 1
return -1, iterations


if __name__ == '__main__':
List = [1, 2, 3, 4, 5, 6, 7, 8]
target = 3
ans = sequentialSearch(target, List)
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Non-Standard Abbreviation

The variable name 'ans' is a common but non-standard abbreviation for 'answer'. Expanding it to 'result' or 'position' would improve semantic clarity.

Suggested change
ans = sequentialSearch(target, List)
result = sequentialSearch(target, items)
Reasons & Gaps

Reasons

  1. Expanding 'ans' to 'result' aligns with descriptive naming best practices
  2. Reduces cognitive load by using full words instead of clipped abbreviations
  3. Improves maintainability by providing better context for the variable's role

Gaps

  1. 'ans' is widely understood in mathematical or algorithmic contexts
  2. The scope of the variable is very small, reducing the impact of the abbreviation

if ans != -1:
print('Target found at position:',ans,'in',iterations,'iterations')
else:
print('Target not found in the list')
29 changes: 29 additions & 0 deletions Test2/P23_BinarySearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Author: OMKAR PATHAK
#This programs give an example of binary search algorithm

def binarySearch(target, List):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Function Naming Convention Violation

The function name 'binarySearch' uses camelCase, which violates the Python snake_case convention. Additionally, 'List' as a parameter name is a built-in type name and should be more descriptive.

Suggested change
def binarySearch(target, List):
def binary_search(target, sorted_list):
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require function names to be in snake_case
  2. Using 'List' as a parameter name shadows the built-in list type and lacks context
  3. 'binary_search' and 'sorted_list' provide better clarity and follow language standards

Gaps

  1. The function name is technically descriptive of the algorithm being used
  2. camelCase is common in other languages and might be a personal preference of the developer

'''This function performs a binary search on a sorted list and returns the position if successful else returns -1'''
left = 0 #First position of the list
right = len(List) - 1 #Last position of the list
global iterations
iterations = 0
Comment on lines +8 to +9
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 85%

State Management Issue: Global Variable Usage

Using global iterations to track the number of steps is risky. If this function is imported into another module or called in a loop, it relies on a global state that might not be initialized or could be overwritten unexpectedly. It's much safer to return the iteration count along with the result or handle it within a class structure to ensure thread safety and modularity.

Reasons & Gaps

Reasons

  1. Global variables create hidden dependencies between functions and the module state.
  2. Makes the function difficult to test in isolation or use in multi-threaded environments.
  3. Violates encapsulation principles by modifying state outside the function's local scope.

Gaps

  1. The current script is a standalone example where global scope side effects are contained.
  2. Python's global keyword behavior is deterministic within the module scope.


while left <= right: #U can also write while True condition
iterations += 1
mid = (left + right) // 2
if target == List[mid]:
return mid
elif target < List[mid]:
right = mid - 1
else:
left = mid + 1
return -1

if __name__ == '__main__':
List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14]
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 92% View Citation

JAS - Just a suggestion
Vague and Shadowing Variable Name

The variable name 'List' shadows the built-in 'list' type and is capitalized, which usually denotes a class. A name like 'sorted_numbers' would be more expressive.

Suggested change
List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14]
sorted_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14]
Reasons & Gaps

Reasons

  1. Variable names should be lowercase in Python to distinguish them from classes
  2. 'List' is too generic and conflicts with the conceptual built-in type name
  3. 'sorted_list' provides semantic information about the state of the data

Gaps

  1. The variable is used in a simple script where the type is immediately obvious
  2. Capitalization might be an attempt to distinguish it from the keyword 'list'

target = 2
ans = binarySearch(target, List)
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 88% View Citation

JAS - Just a suggestion
Cryptic Abbreviation in Variable Name

The variable name 'ans' is a cryptic abbreviation for 'answer' or 'result'. Using a more descriptive name like 'result_index' or 'target_position' improves code clarity.

Suggested change
ans = binarySearch(target, List)
result_index = binary_search(target, sorted_list)
Reasons & Gaps

Reasons

  1. Cryptic abbreviations increase cognitive load when reading logic flow
  2. 'result_index' explicitly describes what the value represents (the index of the target)
  3. Avoids non-standard abbreviations as per enterprise maintainability standards

Gaps

  1. 'ans' is a very common abbreviation in competitive programming or mathematical scripts
  2. The local scope of the variable makes its purpose relatively easy to infer

if(ans != -1):
print('Target found at position:',ans,'in',iterations,'iterations')
else:
print('Target not found')
21 changes: 21 additions & 0 deletions Test2/P24_SelectionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#Author: OMKAR PATHAK
#This program shows an example of selection sort

#Selection sort iterates all the elements and if the smallest element in the list is found then that number
#is swapped with the first

#Best O(n^2); Average O(n^2); Worst O(n^2)

def selectionSort(List):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Function Naming Convention

In Python, function names should follow the snake_case convention. Additionally, 'selectionSort' could be more descriptive, such as 'sort_list_using_selection_sort'.

Suggested change
def selectionSort(List):
def selection_sort(input_list):
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require snake_case for function names
  2. Using 'List' as a parameter name shadows the built-in list type
  3. Descriptive names like 'selection_sort' improve maintainability and follow language standards

Gaps

  1. The function name is technically understandable within the context of the file's comments
  2. CamelCase is common in other languages, though discouraged in Python PEP 8 standards

Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Vague Variable Name

The variable name 'List' is a generic type name and shadows the built-in Python list. Use a more descriptive name like 'unsorted_list' or 'elements'.

Suggested change
def selectionSort(List):
def selection_sort(elements):
Reasons & Gaps

Reasons

  1. Shadowing built-in types like 'list' can lead to confusing errors or restricted functionality
  2. Generic names like 'List' do not describe the specific content or state of the data
  3. Expressive names like 'elements' or 'input_list' enhance semantic clarity

Gaps

  1. 'List' is capitalized, which usually denotes a class, but here it is used as a parameter
  2. The context of a sorting algorithm makes the purpose of the variable clear despite the name

for i in range(len(List) - 1): #For iterating n - 1 times
minimum = i
for j in range( i + 1, len(List)): # Compare i and i + 1 element
if(List[j] < List[minimum]):
minimum = j
if(minimum != i):
List[i], List[minimum] = List[minimum], List[i]
return List

if __name__ == '__main__':
List = [3, 4, 2, 6, 5, 7, 1, 9]
print('Sorted List:',selectionSort(List))
24 changes: 24 additions & 0 deletions Test2/P25_BubbleSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#Author: OMKAR PATHAK
#This program shows an example of bubble sort using Python

# Bubblesort is an elementary sorting algorithm. The idea is to
# imagine bubbling the smallest elements of a (vertical) array to the
# top; then bubble the next smallest; then so on until the entire
# array is sorted. Bubble sort is worse than both insertion sort and
# selection sort. It moves elements as many times as insertion sort
# (bad) and it takes as long as selection sort (bad). On the positive
# side, bubble sort is easy to understand. Also there are highly
# improved variants of bubble sort.

# Best O(n^2); Average O(n^2); Worst O(n^2)

def bubbleSort(List):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Non-Descriptive Variable Name

The parameter name 'List' is a generic type name and does not describe the content or purpose of the data. Using descriptive names like 'numbers' or 'input_elements' improves code clarity.

Suggested change
def bubbleSort(List):
def bubbleSort(input_list):
Reasons & Gaps

Reasons

  1. Using 'List' as a variable name shadows the built-in Python type
  2. Generic names fail to communicate the domain context of the data being sorted
  3. Descriptive names reduce cognitive load when reading the function implementation

Gaps

  1. 'List' is a built-in type name in Python, which can lead to shadowing issues
  2. The context of a sorting algorithm makes the purpose of the variable relatively clear

for i in range(len(List)):
for j in range(len(List) - 1, i, -1):
if List[j] < List[j - 1]:
List[j], List[j - 1] = List[j - 1], List[j]
return List
Comment on lines +15 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 100%

JAS - Just a suggestion
Performance Optimization: Missing Early Exit

I notice that this implementation of Bubble Sort always runs in O(n²) time, even if the list becomes sorted early. We can optimize this by adding a flag to check if any swaps occurred during a pass. If no swaps happen, the list is already sorted, and we can exit early. This improves the best-case time complexity to O(n).

Suggested change
def bubbleSort(List):
for i in range(len(List)):
for j in range(len(List) - 1, i, -1):
if List[j] < List[j - 1]:
List[j], List[j - 1] = List[j - 1], List[j]
return List
def bubbleSort(List):
for i in range(len(List)):
swapped = False
for j in range(len(List) - 1, i, -1):
if List[j] < List[j - 1]:
List[j], List[j - 1] = List[j - 1], List[j]
swapped = True
if not swapped:
break
return List


if __name__ == '__main__':
List = [3, 4, 2, 6, 5, 7, 1, 9]
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Vague Generic Variable Name

The variable name 'List' is too generic and shadows the built-in Python type. A more descriptive name like 'unsorted_numbers' or 'sample_data' would be more expressive.

Suggested change
List = [3, 4, 2, 6, 5, 7, 1, 9]
unsorted_numbers = [3, 4, 2, 6, 5, 7, 1, 9]
Reasons & Gaps

Reasons

  1. 'List' is a functional generic name that lacks semantic meaning about the data
  2. Shadowing built-in types is a poor practice that can cause confusion in larger scopes
  3. Expressive names like 'unsorted_numbers' clarify the intent of the test data

Gaps

  1. In a small script, the variable's purpose is immediately obvious from the assignment
  2. Shadowing 'List' is a technical concern but doesn't break this specific logic

print('Sorted List:',bubbleSort(List))
25 changes: 25 additions & 0 deletions Test2/P26_InsertionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#Author: OMKAR PATHAK
#This program shows an example of insertion sort using Python

# Insertion sort is good for collections that are very small
# or nearly sorted. Otherwise it's not a good sorting algorithm:
# it moves data around too much. Each time an insertion is made,
# all elements in a greater position are shifted.

# Best O(n); Average O(n^2); Worst O(n^2)

def insertionSort(List):
Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Violates Language-Specific Case Convention

In Python, function names should follow the snake_case convention. The current name insertionSort uses camelCase, which is more common in Java or JavaScript.

Suggested change
def insertionSort(List):
def insertion_sort(List):
Reasons & Gaps

Reasons

  1. PEP 8 recommends using lowercase words separated by underscores for function names
  2. Consistent naming conventions improve code maintainability and readability for Python developers
  3. Adhering to language-specific standards reduces cognitive load during code reviews

Gaps

  1. The project might be following a legacy naming convention that overrides PEP 8 standards
  2. The developer might be transitioning from a camelCase-dominant language like Java

Copy link
Contributor

Choose a reason for hiding this comment

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

JAS Confidence Score: 90% View Citation

JAS - Just a suggestion
Forbidden Generic Name

The variable name 'List' is a forbidden generic name and also conflicts with the built-in type list in Python. Using descriptive names like numbers or elements is recommended.

Suggested change
def insertionSort(List):
def insertionSort(items):
Reasons & Gaps

Reasons

  1. 'List' is a generic term that doesn't describe the contents of the collection
  2. Shadowing or mimicking built-in type names can lead to confusion and potential bugs
  3. Descriptive names like 'items' or 'collection' provide better context for the data

Gaps

  1. In very small utility functions, generic names are sometimes tolerated by developers
  2. The variable is used consistently as a list, which might be the developer's justification

for i in range(1, len(List)):
currentNumber = List[i]
for j in range(i - 1, -1, -1):
if List[j] > currentNumber :
List[j], List[j + 1] = List[j + 1], List[j]
else:
List[j + 1] = currentNumber
break
Comment on lines +14 to +19
Copy link
Contributor

Choose a reason for hiding this comment

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

Warning Confidence Score: 90%

Logical Error in Insertion Sort Implementation

I notice a potential logic issue in how the currentNumber is handled. In the if block, we are swapping elements, but in the else block, we explicitly assign currentNumber to List[j + 1]. If the if condition is met and a swap occurs, the value originally in currentNumber is moved, but the variable currentNumber itself isn't updated. This mix of swapping and explicit assignment can lead to incorrect values being placed in the list if the logic isn't consistent. A cleaner approach for Insertion Sort is to shift elements and then place the currentNumber once.

Suggested change
for j in range(i - 1, -1, -1):
if List[j] > currentNumber :
List[j], List[j + 1] = List[j + 1], List[j]
else:
List[j + 1] = currentNumber
break
j = i - 1
while j >= 0 and List[j] > currentNumber:
List[j + 1] = List[j]
j -= 1
List[j + 1] = currentNumber
Reasons & Gaps

Reasons

  1. Standard insertion sort logic involves shifting elements rather than multiple swaps for efficiency.
  2. Mixing swaps with explicit assignments of a cached variable can lead to data duplication or loss.
  3. The current loop structure makes it difficult to ensure the 'currentNumber' is always placed correctly.

Gaps

  1. The current implementation might work for some inputs due to the swap, but it is non-standard and prone to errors.
  2. The interaction between the swap at line 16 and the assignment at line 18 is logically fragile.


return List

if __name__ == '__main__':
List = [3, 4, 2, 6, 5, 7, 1, 9]
print('Sorted List:',insertionSort(List))
Loading
Loading