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
2 changes: 2 additions & 0 deletions Programs/P02_VariableScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def test():
y = 100 # Local y
x = 20
print(x + y) #prints 'Local x' and 'Local y'
print("Variable scope")

if __name__ == '__main__':
test()
print(x) #prints 'Global x'

19 changes: 19 additions & 0 deletions Test001/P10_LCM.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Author: OMKAR PATHAK
#This program calculates the LCM of the two numbers entered by the user

def LCM(number1, number2):
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
Function Naming Convention

The function name 'LCM' uses all uppercase letters, which violates Python's snake_case naming convention. It should be renamed to something more descriptive and idiomatic like 'calculate_lcm'.

Suggested change
def LCM(number1, number2):
def calculate_lcm(number1, number2):
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require function names to be in lowercase snake_case
  2. 'calculate_lcm' explicitly describes the action being performed by the function
  3. Improves consistency with standard Python library naming patterns

Gaps

  1. LCM is a well-known mathematical acronym which might be considered acceptable in some scientific contexts
  2. The project might not strictly enforce PEP 8 snake_case for mathematical abbreviations

'''This function calculates LCM of two numbers inputed by the user'''
maximum = max(number1, number2)
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%

Division by Zero Risk

I noticed that if a user enters '0' as one of the numbers, the program will crash with a ZeroDivisionError during the modulo operation. We should add a check to handle zero inputs, as the LCM of any number and zero is typically defined as zero or undefined depending on the context.

Suggested change
maximum = max(number1, number2)
if number1 == 0 or number2 == 0:
return 0
maximum = max(number1, number2)

i = maximum
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: 80% View Citation

JAS - Just a suggestion
Single-Character Variable Name

The variable name 'i' is used here as a tracking value for the LCM calculation rather than a simple loop counter. Using a more descriptive name like 'current_multiple' would improve code clarity.

Suggested change
i = maximum
current_multiple = maximum
Reasons & Gaps

Reasons

  1. Single-letter names (except for simple loop indices) increase cognitive load for maintainers
  2. 'current_multiple' clearly indicates the variable's role in the LCM search logic
  3. Descriptive names make the algorithm's intent self-documenting without needing extra comments

Gaps

  1. 'i' is commonly used for integers in mathematical algorithms without causing significant confusion
  2. The scope of the variable is very small, making its purpose relatively easy to trace

while True:
if (i % number1 == 0 and i % number2 == 0):
lcm = i
break
i += maximum

return lcm

if __name__ == '__main__':
userInput1 = int(input('Enter first 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
Variable Naming Refinement

The variable 'userInput1' uses camelCase, which is inconsistent with Python's snake_case convention. Additionally, 'first_number' would be more descriptive of the data's role.

Suggested change
userInput1 = int(input('Enter first number: '))
first_number = int(input('Enter first number: '))
Reasons & Gaps

Reasons

  1. CamelCase (userInput1) deviates from the standard Python snake_case (user_input_1) convention
  2. 'first_number' is more semantically accurate than the generic 'userInput1'
  3. Consistent naming styles across the file improve professional code quality

Gaps

  1. The name is functional and understandable, making this a low-priority refinement
  2. Some developers prefer camelCase if they are coming from Java or JavaScript backgrounds

userInput2 = int(input('Enter second number: '))
print('LCM of {} and {} is {}'.format( userInput1, userInput2, LCM(userInput1, userInput2)))
17 changes: 17 additions & 0 deletions Test001/P11_BinaryToDecimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Author: OMKAR PATHAK
#This program converts the given binary number to its decimal equivalent

def binaryToDecimal(binary):
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 name 'binaryToDecimal' uses camelCase which is non-idiomatic in Python. Additionally, if this function were to return a boolean check, it would require a prefix like 'is_'. However, per Python standards (PEP 8), function names should be snake_case.

Suggested change
def binaryToDecimal(binary):
def binary_to_decimal(binary):
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require function names to be in snake_case
  2. camelCase is typically reserved for other languages like Java or JavaScript
  3. Consistent naming improves maintainability and follows community standards

Gaps

  1. The standard CS-2 focuses on boolean prefixes and vague verbs; while this is a naming convention issue, it fits the 'incorrect case' criteria
  2. Python functions should strictly follow snake_case per PEP 8 guidelines

'''This function calculates the decimal equivalent to given binary number'''
binary1 = binary
decimal, i, n = 0, 0, 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 Names

The variables 'i' and 'n' are single-character names. While 'i' is often used as a loop counter, 'n' is unused in the provided logic and both should be more descriptive to improve code clarity.

Suggested change
decimal, i, n = 0, 0, 0
decimal, power_index = 0, 0
Reasons & Gaps

Reasons

  1. Single-letter variables (except in specific loop contexts) reduce code readability
  2. Descriptive names like 'power_index' explain the variable's role in the binary conversion
  3. Removing unused variables like 'n' reduces cognitive load and potential for bugs

Gaps

  1. 'i' is a common convention for indices, but 'power_index' is more descriptive in this mathematical context
  2. 'n' is initialized but never used in the visible logic

while(binary != 0):
dec = binary % 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: 80% View Citation

JAS - Just a suggestion
Non-Standard Abbreviation

The variable name 'dec' is a non-standard abbreviation for 'decimal' or 'digit'. Expanding it to 'remainder' or 'binary_digit' would make the logic more explicit.

Suggested change
dec = binary % 10
binary_digit = binary % 10
Reasons & Gaps

Reasons

  1. Abbreviations like 'dec' can be ambiguous (could mean decimal, decrease, or declaration)
  2. Fully expressive names like 'binary_digit' clarify the data being processed
  3. Standardizing naming reduces the time required for new developers to understand the logic

Gaps

  1. 'dec' is understandable in context but violates the preference for fully expressive names
  2. The term 'digit' is more accurate for the result of a modulo 10 operation

decimal = decimal + dec * pow(2, i)
Comment on lines +8 to +10
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%

Missing Validation for Non-Binary Digits

I noticed that the current implementation doesn't check if the input contains digits other than 0 or 1. If a user enters a number like '123', the logic will still process it as if it were binary, leading to mathematically incorrect results. We should add a check to ensure the input is a valid binary number before processing.

Suggested change
while(binary != 0):
dec = binary % 10
decimal = decimal + dec * pow(2, i)
while(binary != 0):
dec = binary % 10
if dec not in (0, 1):
print('Invalid binary number')
return
decimal = decimal + dec * pow(2, i)

binary = binary//10
i += 1
print('Decimal equivalent of {} is {}'.format(binary1, decimal))

if __name__ == '__main__':
userInput = int(input('Enter the binary number to check its decimal equivalent: '))
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
Mixed Case Naming Convention

The variable 'userInput' uses camelCase, which is inconsistent with Python's snake_case convention for variables.

Suggested change
userInput = int(input('Enter the binary number to check its decimal equivalent: '))
user_input = int(input('Enter the binary number to check its decimal equivalent: '))
Reasons & Gaps

Reasons

  1. Python variables should follow the snake_case convention per PEP 8
  2. Mixed naming styles (camelCase vs snake_case) make the codebase look unpolished
  3. Standardized naming facilitates better integration with linting tools

Gaps

  1. The variable is functional and clear, but violates the language-specific style guide
  2. Consistency across the codebase is the primary driver for this refinement

binaryToDecimal(userInput)
13 changes: 13 additions & 0 deletions Test001/P12_DecimalToBinary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Author: OMKAR PATHAK
#Program to convert decimal to its equivalent binary

def decimalToBinary(n):
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 Parameter Name

The parameter name 'n' is a single character, which is non-descriptive. Using a more meaningful name like 'decimal_number' improves code readability and intent.

Suggested change
def decimalToBinary(n):
def decimalToBinary(decimal_number):
Reasons & Gaps

Reasons

  1. Single-character names provide no context about the data type or purpose
  2. Descriptive names reduce cognitive load when reading complex logic
  3. Standard naming improves maintainability for other developers

Gaps

  1. Single-letter variables like 'n' are common in mathematical or recursive contexts
  2. The function name already implies the purpose of the input parameter

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
Function Naming Convention (Case Style)

Python function names should follow snake_case. 'decimalToBinary' uses camelCase, which deviates from standard Python naming conventions.

Suggested change
def decimalToBinary(n):
def decimal_to_binary(n):
Reasons & Gaps

Reasons

  1. PEP 8 specifically recommends snake_case for function and method names
  2. Adhering to language-specific conventions makes the code more idiomatic
  3. Consistent naming styles improve the overall professional quality of the code

Gaps

  1. The developer may be following a specific internal style guide that prefers camelCase
  2. Function naming is often a matter of team preference despite PEP 8

'''Function to print binary number for the input decimal using recursion'''
if n > 1:
decimalToBinary(n//2)
print(n % 2,end = '')

if __name__ == '__main__':
userInput = int(input('Enter the decimal number to find its binary equivalent: '))
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
Naming Convention Inconsistency

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

Suggested change
userInput = int(input('Enter the decimal number to find its binary equivalent: '))
user_input = int(input('Enter the decimal number to find its binary equivalent: '))
Reasons & Gaps

Reasons

  1. Python community standards (PEP 8) mandate snake_case for variables
  2. Consistent casing across the codebase prevents confusion and stylistic drift
  3. Improves integration with standard Python linting and analysis tools

Gaps

  1. Project-specific style guides might allow camelCase for consistency with other languages
  2. The variable is functional and descriptive despite the casing style

decimalToBinary(userInput)
Comment on lines +11 to +12
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 Error: Missing Input Validation

I notice we're directly casting the user input to an integer. If a user enters a non-numeric string or a float, the program will crash with a ValueError. We should wrap this in a try-except block to handle invalid inputs gracefully.

Suggested change
userInput = int(input('Enter the decimal number to find its binary equivalent: '))
decimalToBinary(userInput)
try:
userInput = int(input('Enter the decimal number to find its binary equivalent: '))
decimalToBinary(userInput)
except ValueError:
print('Invalid input! Please enter a valid integer.')

print()
14 changes: 14 additions & 0 deletions Test001/P13_Palindrome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Author: OMKAR PATHAK
#This program checks for the palindrome

def palindrome(string):
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
Boolean Function Naming

Functions that check a condition and imply a boolean result should typically be prefixed with 'is_', 'has_', or 'can_'. Renaming to 'is_palindrome' makes the intent clearer.

Suggested change
def palindrome(string):
def is_palindrome(string):
Reasons & Gaps

Reasons

  1. Function names should be verbs or verb phrases describing the action
  2. Predicate functions are more readable when prefixed with boolean indicators
  3. 'palindrome' as a name is a noun, which usually represents a variable or class

Gaps

  1. The function currently prints the result instead of returning a boolean
  2. If the intent is a CLI utility, a noun-based name might be acceptable

'''This function checks the string for palindrome'''
revString = string[::-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%

Case-Sensitive Palindrome Check

I notice the current implementation performs a case-sensitive check. This means 'Level' would not be recognized as a palindrome because 'L' and 'l' are different characters. We should normalize the string to lowercase to ensure the check works as expected for all inputs.

Suggested change
revString = string[::-1]
string = string.lower()
revString = string[::-1]

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
Variable Naming Convention

The variable name 'revString' uses camelCase, which is not the standard naming convention for Python. Following PEP 8, variable names should use snake_case (e.g., 'reversed_string').

Suggested change
revString = string[::-1]
reversed_string = string[::-1]
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require snake_case for variable names
  2. Using 'rev' as a prefix is a mixed abbreviation pattern that reduces clarity
  3. Consistent naming styles across the module improve long-term maintainability

Gaps

  1. The term 'rev' is a common clipping for 'reversed' but 'reversed_string' is more expressive
  2. Project-specific style guides might occasionally allow camelCase in Python for consistency with other languages

if string == revString:
print('String is Palindrome')
else:
print('String is not Palindrome')

if __name__ == '__main__':
userInput = str(input('Enter a string to check for Palindrome: '))
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

The variable name 'userInput' uses camelCase. In Python, the standard convention for variables is snake_case. Consider renaming it to 'user_input'.

Suggested change
userInput = str(input('Enter a string to check for Palindrome: '))
user_input = str(input('Enter a string to check for Palindrome: '))
Reasons & Gaps

Reasons

  1. PEP 8 style guide explicitly recommends snake_case for all variable names
  2. Maintaining language-specific conventions reduces cognitive load for Python developers
  3. Standardized naming prevents mixed styles within the same codebase

Gaps

  1. camelCase is technically functional but violates Python-specific style standards
  2. The name is descriptive, so the violation is purely stylistic rather than semantic

palindrome(userInput)
15 changes: 15 additions & 0 deletions Test001/P14_CheckGreater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Author: OMKAR PATHAK
#This prpgram checks that the given number is greater than all those numbers in th list

def checkGreater(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
Boolean-Returning Function Without Prefix

The function returns a boolean-like result (implicit check) or performs a validation but lacks a boolean prefix like 'is_' or 'has_'. In Python, 'is_greater_than_list' would be more idiomatic.

Suggested change
def checkGreater(number):
def is_greater_than_list(number):
Reasons & Gaps

Reasons

  1. Function names should clearly indicate if they perform a check or return a boolean value
  2. Adding a prefix like 'is_' improves the predictability of the function's behavior
  3. 'checkGreater' uses camelCase which is non-idiomatic for Python function definitions

Gaps

  1. The function currently prints instead of returning a boolean, making the prefix rule partially applicable
  2. Standard naming conventions for utility functions often vary by team preference

'''This function checks whether the entered number is greater than those in the list'''
original = [1,2,3,4,5]
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: 78% View Citation

JAS - Just a suggestion
Vague Variable Name

The variable name 'original' is functional but generic. A more descriptive name like 'reference_numbers' or 'comparison_list' would better reflect its purpose in this logic.

Suggested change
original = [1,2,3,4,5]
reference_numbers = [1,2,3,4,5]
Reasons & Gaps

Reasons

  1. 'original' does not describe what the data represents, only its state relative to changes
  2. Descriptive names like 'reference_numbers' explain the business logic role of the variable
  3. Improving semantic clarity helps maintainability as the function grows in complexity

Gaps

  1. In a very small function, 'original' might be considered sufficiently clear by some reviewers
  2. The context of the list is simple enough that ambiguity is relatively low

original.sort()
if number > original[-1]:
print('Yes, the entered number is greater than those in the list')
else:
print('No, entered number is less than those in the list')
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%

Inaccurate Logic in Failure Message

I noticed a small logic issue in the else block. If the entered number is equal to the largest number in the list, the current message says it is 'less than', which is technically incorrect. We should update the message to accurately reflect that the number is 'less than or equal to' the list elements to avoid confusing the user.

Suggested change
print('No, entered number is less than those in the list')
print('No, entered number is less than or equal to those in the list')


if __name__ == '__main__':
userInput = int(input('Enter the 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
Non-Standard Case Convention

Python variables should use snake_case instead of camelCase. 'user_input' is the preferred naming convention for local variables in Python.

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

Reasons

  1. PEP 8 specifically recommends snake_case for variable and function names in Python
  2. Consistent casing reduces cognitive load when switching between different Python modules
  3. 'user_input' aligns with standard Python library and community naming patterns

Gaps

  1. Project-specific style guides might allow camelCase for consistency with older codebases
  2. The variable name itself is descriptive, only the casing style is technically incorrect

checkGreater(userInput)
17 changes: 17 additions & 0 deletions Test001/P15_Arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Author: OMKAR PATHAK
#This program gives a demo of how can you pass arguments while running python programs
#Run the program as: python P15_Arguments.py Omkar Pathak

import sys

def arguments():
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 Function Name

The function name 'arguments' is a generic noun that doesn't describe the action being performed. Renaming it to something like 'print_command_line_arguments' would better reflect its purpose.

Suggested change
def arguments():
def print_command_line_arguments():
Reasons & Gaps

Reasons

  1. Function names should ideally be verbs or verb phrases describing an action
  2. 'arguments' is a noun and doesn't communicate that the function prints them
  3. Descriptive names act as documentation and reduce cognitive load for maintainers

Gaps

  1. The function is small and its purpose is clear from the docstring
  2. In a script specifically about arguments, the name might be considered contextually sufficient

'''This function prints the argruments passed while running the python program'''
try:
print('This is the name of the script:', sys.argv[0])
print('First argument:', sys.argv[1])
print('Second argument:', sys.argv[2])
except IndexError:
print('Give only two arguments')
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 IndexError for Command-Line Arguments

I notice we're accessing sys.argv[1] and sys.argv[2] inside the try block, but the error message in the except block says 'Give only two arguments'. Actually, if the user provides fewer than two arguments, an IndexError will occur. The message should probably clarify that at least two arguments are required to avoid confusion when the script fails due to missing inputs.

Suggested change
print('Give only two arguments')
print('Please provide at least two arguments (e.g., Omkar Pathak)')


if __name__ == '__main__':
arguments()
17 changes: 17 additions & 0 deletions Test001/P16_CountVowels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Author: OMKAR PATHAK
#This program counts the vowels present in the user input

def countVowels(sentence):
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 (Python)

In Python, function names should follow the snake_case convention as per PEP 8. Consider renaming countVowels to count_vowels to align with standard Python practices.

Suggested change
def countVowels(sentence):
def count_vowels(sentence):
Reasons & Gaps

Reasons

  1. Python's PEP 8 standard explicitly recommends snake_case for function names
  2. Consistent naming conventions improve code searchability and developer onboarding
  3. camelCase is non-idiomatic in Python and deviates from standard library patterns

Gaps

  1. The project might be using camelCase as a local convention inherited from other languages
  2. The impact on functionality is zero, making this a stylistic preference check

'''This function counts the vowels'''
count = 0
sentence = sentence.lower()
for c in sentence:
if c in ['a', 'e', 'i', 'o', 'u']:
count += 1
return count


if __name__ == '__main__':
userInput = str(input("Enter the string to check for vowels: "))
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
Redundant Type Casting

I noticed we're using str(input(...)) here. In Python 3, the input() function already returns a string by default, so wrapping it in str() is redundant and doesn't change the behavior. We can simplify this to just input(...) for cleaner code.

Suggested change
userInput = str(input("Enter the string to check for vowels: "))
userInput = input("Enter the string to check for vowels: ")

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 (Python)

Variable names in Python should use snake_case. Renaming userInput to user_input follows PEP 8 guidelines and improves consistency across the Python ecosystem.

Suggested change
userInput = str(input("Enter the string to check for vowels: "))
user_input = str(input("Enter the string to check for vowels: "))
Reasons & Gaps

Reasons

  1. PEP 8 specifies that variable names should be lowercase with words separated by underscores
  2. Using snake_case ensures the codebase remains idiomatic for Python developers
  3. Improves visual consistency with other standard Python variables and functions

Gaps

  1. camelCase is often used by developers coming from Java/JavaScript backgrounds
  2. The variable is local to the main block, reducing the scope of the inconsistency

count = countVowels(userInput)
print('Vowel Count: ',count)
19 changes: 19 additions & 0 deletions Test001/P17_EvenOdd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Author: OMKAR PATHAK
#This program takes input from user and sorts the numbers in two arrays, one of even and other of odd

def evenOdd(numbers):
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
Boolean-Returning Function Without Prefix

The function name 'evenOdd' returns a tuple of lists but its name is ambiguous. If it were intended to check a property, it would require a prefix like 'is_'. However, per standard CS-2 rule 1.2, functions returning specific logic should follow naming conventions. More importantly, it violates Python's snake_case convention.

Suggested change
def evenOdd(numbers):
def get_even_and_odd_numbers(numbers):
Reasons & Gaps

Reasons

  1. Function name 'evenOdd' uses camelCase which violates Python snake_case conventions
  2. The name is vague and doesn't clearly indicate that it performs a separation/filtering action
  3. Descriptive names like 'get_even_and_odd_numbers' improve code maintainability and intent

Gaps

  1. The function returns a tuple, not a boolean, so the boolean prefix rule (1.2) is a partial match
  2. The primary issue is the camelCase naming in a Python context which violates rule 5

'''This function divides the numbers in two arrays one of even and other of odd'''
even = []
odd = []
for number in numbers:
if int(number) % 2 == 0:
even.append(number)
else:
odd.append(number)
Comment on lines +9 to +12
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%

Potential Runtime Error on Non-Numeric Input

I noticed that we're calling int(number) directly on user input without any validation. If a user accidentally enters a letter or a special character instead of a number, the program will crash with a ValueError. It would be much safer to check if the input is numeric before attempting the conversion to ensure the script doesn't fail unexpectedly.

Suggested change
if int(number) % 2 == 0:
even.append(number)
else:
odd.append(number)
try:
num = int(number)
if num % 2 == 0:
even.append(number)
else:
odd.append(number)
except ValueError:
continue
Reasons & Gaps

Reasons

  1. Direct type casting of unvalidated user input causes immediate runtime crashes
  2. ValueError is raised when non-numeric strings are passed to the int() constructor
  3. Missing error handling prevents the script from processing remaining valid numbers

Gaps

  1. The intended use case might strictly assume valid integer inputs from a controlled source
  2. Adding try-except blocks might slightly change the function's return behavior for invalid data

return even, odd

if __name__ == '__main__':
userInput = input("Enter the numbers (space separated) 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 Violation

The variable 'userInput' uses camelCase, which violates the standard Python snake_case naming convention. Additionally, while descriptive, it can be refined to better match the domain of the script.

Suggested change
userInput = input("Enter the numbers (space separated) to check: ")
user_input = input("Enter the numbers (space separated) to check: ")
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) require variables to be in snake_case format
  2. Mixed case styles like camelCase reduce consistency in a Python-centric codebase
  3. Standardizing to 'user_input' aligns with enterprise readability requirements

Gaps

  1. The name is descriptive of the source but not the content (numbers)
  2. Project-specific style guides might occasionally allow camelCase, though PEP 8 discourages it

userInput = list(userInput.split())
even, odd = evenOdd(userInput)
print('Even Nos: ', ','.join(even), '\n', 'Odd Nos: ', ','.join(odd))
22 changes: 22 additions & 0 deletions Test001/P18_Logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Author: OMKAR PATHAK
#This program illustrates a logging example
import logging

def log(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
Vague Function Name

The function name 'log' is a generic verb that doesn't clearly describe its specific action or target. Renaming it to something like 'log_even_odd_status' would better reflect its purpose of checking parity and logging results.

Suggested change
def log(number):
def log_even_odd_status(number):
Reasons & Gaps

Reasons

  1. Generic verbs like 'log' without a noun fail to communicate the function's specific intent
  2. Descriptive names act as internal documentation, reducing the need to read the function body
  3. Specific naming prevents ambiguity when the codebase grows or more logging functions are added

Gaps

  1. The term 'log' is contextually common in logging-specific scripts
  2. Small script scope makes the function's purpose relatively easy to infer from the body

''' This function creates a log file if any error is reported '''
logging.basicConfig(filename = 'P18-logfile.txt', level = logging.INFO)
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%

Ineffective Logging Configuration

I notice that logging.basicConfig is called inside the log function. In Python, basicConfig only configures the logger if it hasn't been configured yet. If this function is called multiple times, subsequent calls will be ignored, which might lead to unexpected logging behavior if other parts of the app try to reconfigure it. It's generally better to configure logging at the module level or once at the start of the application.

Reasons & Gaps

Reasons

  1. basicConfig is a one-time configuration call that ignores subsequent invocations
  2. Placing configuration inside a function prevents consistent logging across the module
  3. Can lead to silent failures where log settings are not applied as expected

Gaps

  1. The script is small and likely standalone, making the impact of repeated configuration calls negligible in this specific context.
  2. Standard logging behavior in simple scripts often involves local configuration despite best practices.

try:
if int(number) % 2 == 0:
print('Successful')
else:
print('Unsuccessful, this instance will be reported, check the log file')
logging.info('Invalid Entry')
except:
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%

Bare Exception Clause

I see we're using a bare except: block here. This is a bit risky because it catches every possible exception, including KeyboardInterrupt or SystemExit, which can make it hard for a user to stop the program. It's safer to catch specific errors like ValueError or TypeError so we only handle the issues we actually expect.

Suggested change
except:
except (ValueError, TypeError):

print('Please enter a valid integer')

if __name__ == '__main__':
try:
userInput = int(input('Enter a 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: 95% View Citation

JAS - Just a suggestion
Inconsistent Naming Convention (CamelCase in Python)

Python variables should follow the snake_case convention. 'userInput' uses camelCase, which is inconsistent with standard Python style guides like PEP 8.

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

Reasons

  1. PEP 8 explicitly recommends snake_case for variable and function names in Python
  2. Consistent casing improves code maintainability and reduces cognitive load for Python developers
  3. Standardizing naming conventions ensures the codebase looks professional and idiomatic

Gaps

  1. Project-specific style guides might occasionally allow camelCase for consistency with other languages
  2. The variable is functional and its meaning is clear despite the casing violation

log(userInput)
except:
print('Please enter a valid integer')
45 changes: 45 additions & 0 deletions Test001/P19_SimpleStopWatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#Author: OMKAR PATHAK
#This program illustrates a stopwatch

import time

print('Press ENTER to begin, Press Ctrl + C to stop')
while True:
try:
input() #For ENTER
starttime = time.time()
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 in Variable Name

The variable name starttime uses a concatenated form. Following Python's snake_case convention and improving clarity, start_time is preferred.

Suggested change
starttime = time.time()
start_time = time.time()
Reasons & Gaps

Reasons

  1. Python naming conventions (PEP 8) recommend using underscores to separate words in variables
  2. Improving semantic clarity by separating 'start' and 'time' enhances code professional standards
  3. Consistent use of snake_case improves readability for developers accustomed to Python patterns

Gaps

  1. The term 'starttime' is widely understood in programming contexts despite missing an underscore
  2. Small script scope makes the current naming functional and low-risk for maintainability

print('Started')
Comment on lines +8 to +11
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 UnboundLocalError on Interrupt

I notice that if a user presses Ctrl + C before the first input() is resolved, the starttime variable won't be defined. This will cause the program to crash when it tries to access starttime in the except block. We should initialize starttime before the try block or handle the case where it hasn't been set yet.

Suggested change
try:
input() #For ENTER
starttime = time.time()
print('Started')
starttime = time.time()
try:
input() #For ENTER
print('Started')

except KeyboardInterrupt:
print('Stopped')
endtime = time.time()
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 in Variable Name

The variable name endtime should be refined to end_time to align with standard Python naming conventions and improve readability.

Suggested change
endtime = time.time()
end_time = time.time()
Reasons & Gaps

Reasons

  1. Separating words with underscores follows the idiomatic Python snake_case naming style
  2. Enhances the expressiveness of the variable name by clearly defining the two components
  3. Maintains consistency with other time-related variables if they are updated to snake_case

Gaps

  1. 'endtime' is a common compound word in many codebases and is easily understood
  2. The impact on logic is zero, making this a purely stylistic/readability improvement

print('Total Time:', round(endtime - starttime, 2),'secs')
break
# Press enter to start and stop the watch
"""
import time

print('Press Enter to begin, Press Enter again to stop')
if input()=='':
starttime = time.time()
print('Started')
while True:
val=input() #For ENTER
if val=='':
print('Stopped')
endtime = time.time()
print('Total Time:', round(endtime - starttime, 2),'secs')
break

"""

"""
Output:
Press Enter to begin, Press Enter again to stop

Started

Stopped
Total Time: 1.05 secs

"""

13 changes: 13 additions & 0 deletions Test001/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 Crash: Directory Already Exists

I notice we're calling os.mkdir('newDir1') without checking if it already exists. If this script is run a second time, it will throw an FileExistsError and crash. We should add a check or use exist_ok=True if using os.makedirs 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: 75% View Citation

JAS - Just a suggestion
Single-Character Loop Variable

While 'i' is a common convention for simple counters, using a more descriptive name like 'directory_index' or 'folder_number' improves code clarity, especially when performing file system operations.

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

Reasons

  1. Single-letter variables provide no context about the data being iterated
  2. Descriptive names like 'directory_index' clarify the variable's role in the logic
  3. Improves maintainability by making the loop's purpose self-evident to other developers

Gaps

  1. Exemption 1.1 explicitly allows 'i' as a loop counter in range-based loops
  2. The standard suggests avoiding single letters but provides a specific exception for this exact context

print('Here i is',i)
os.rename('newDir' + str(i),'newDir' + str(i + 1))
Comment on lines +9 to +12
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: 95%

Logic Error: Renaming Non-Existent Directories

In the loop, we're trying to rename newDir1 to newDir2, then newDir2 to newDir3, and so on. However, we only created newDir1 outside the loop. On the second iteration (i=2), the script will look for newDir2 to rename it, but it won't find it because the previous iteration already moved it. This will cause a FileNotFoundError.

Suggested change
os.mkdir('newDir1')
for i in range(1,10):
print('Here i is',i)
os.rename('newDir' + str(i),'newDir' + str(i + 1))
os.mkdir('newDir1')
for i in range(1, 10):
print('Here i is', i)
new_name = 'newDir' + str(i + 1)
os.rename('newDir' + str(i), new_name)
time.sleep(2)
Reasons & Gaps

Reasons

  1. The loop logic assumes source directories exist for every value of i
  2. Only the first directory is created, leading to FileNotFoundError on i=2
  3. Breaks the functional flow of the program immediately after the first step

Gaps

  1. The intended logic might be to create a new directory in each iteration
  2. The current implementation suggests a chain of renames on a single entity

time.sleep(2)
24 changes: 24 additions & 0 deletions Test001/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 Function Name

The function name guess is a generic verb that doesn't fully describe the action. A more descriptive name like play_guessing_game or start_number_guess would better reflect its purpose.

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

Reasons

  1. Function names should explicitly state the action and the object being acted upon
  2. 'guess' could imply a single attempt rather than the entire game logic loop
  3. Descriptive names act as internal documentation, making the entry point clearer

Gaps

  1. In very small scripts, short function names are often considered acceptable by developers
  2. The docstring immediately following the definition clarifies the function's purpose

''' 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.

JAS Confidence Score: 95% View Citation

JAS - Just a suggestion
Variable Naming Convention (camelCase in Python)

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

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

Reasons

  1. PEP 8 recommends snake_case for all function and variable names in Python
  2. Consistent naming conventions reduce cognitive load when switching between Python modules
  3. Standardizing on snake_case ensures the code looks idiomatic to other Python developers

Gaps

  1. Project-specific style guides sometimes override PEP 8 to maintain consistency with legacy code
  2. The variable name is descriptive, only the casing style is technically non-compliant

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%

Range Mismatch in User Prompt

I noticed that the random number is generated between 0 and 21 (inclusive), but the prompt tells the user to enter a number between 0 and 20. This could be confusing if the secret number happens to be 21, as the user wouldn't know to guess it. We should align the prompt with the actual range being used.

Suggested change
number = int(input('Enter the number between 0 to 20: '))
number = int(input('Enter the number between 0 to 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: 95%

Potential Runtime Crash on Invalid Input

Right now, if a user accidentally enters something that isn't a number (like a letter or a symbol), the program will crash with a ValueError. Since this is an interactive game, it would be much better to handle that gracefully so the user can try again without the script stopping.

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

Reasons

  1. Calling int() on non-numeric string input raises a ValueError exception
  2. Unhandled exceptions cause the Python interpreter to terminate immediately
  3. Robust CLI applications should validate user input to prevent unexpected crashes

Gaps

  1. The fix requires a multi-line block which might slightly change the loop structure
  2. Error handling preferences can vary between simple scripts and production code

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 Test001/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: 85% View Citation

JAS - Just a suggestion
Variable Naming Violation: Forbidden Generic Name

The parameter name 'List' is a forbidden generic name and a built-in type in Python. Using it as a variable name can lead to shadowing and reduced readability.

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

Reasons

  1. 'List' is a forbidden generic name according to the enterprise coding standards
  2. Using type names as variables causes confusion for developers and static analysis tools
  3. Descriptive names like 'search_list' clarify the variable's role in the algorithm

Gaps

  1. The variable is used within a small function scope which limits the impact of shadowing
  2. Python is case-sensitive, so 'List' (capitalized) technically avoids shadowing the built-in '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 Violation: Language-Specific Case Convention

The function name 'sequentialSearch' uses camelCase, which violates the Python snake_case convention (PEP 8).

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

Reasons

  1. Python standard PEP 8 requires function names to be in snake_case
  2. Consistent casing across the codebase improves overall maintainability
  3. camelCase is typically reserved for other languages like Java or JavaScript

Gaps

  1. Some legacy codebases or specific project styles may intentionally use camelCase
  2. The logic of the function is perfectly clear despite the casing style

'''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
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%

Global State for Iteration Tracking

I notice we're using a global variable iterations to track the search progress. This can lead to unexpected behavior if the function is called multiple times in a larger system or in a multi-threaded environment, as the state is shared globally. It's generally safer to return the iteration count along with the result or encapsulate it within a class.

Suggested change
return position
return position, iterations
Reasons & Gaps

Reasons

  1. Global variables create hidden dependencies between different parts of the code
  2. Shared state makes the function non-reentrant and difficult to test in isolation
  3. Returning multiple values is the standard Pythonic way to handle auxiliary metadata

Gaps

  1. The script appears to be a standalone educational example where global variables are common
  2. Thread safety might not be a requirement for this specific script's context

position += 1
return -1

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: 80% View Citation

JAS - Just a suggestion
Variable Naming Refinement: Non-Standard Abbreviation

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

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

Reasons

  1. 'ans' is identified as a non-standard abbreviation that should be fully expanded
  2. 'result' or 'search_result' provides better alignment with domain terminology
  3. Improving semantic clarity reduces cognitive load for future maintainers

Gaps

  1. 'ans' is a very common abbreviation in mathematical and algorithmic scripts
  2. The context of the search makes the meaning of the variable relatively clear

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 Test001/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 (Case Style)

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

Suggested change
def binarySearch(target, List):
def binary_search(target, List):
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 follow community standards
  3. Standardizing on snake_case ensures the codebase feels native to Python developers

Gaps

  1. Project-specific style guides might occasionally override PEP 8 for consistency with legacy code
  2. The developer's background in other languages often leads to camelCase usage in Python

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 Variable Name

The variable name List is a forbidden generic name and shadows the built-in list type (case-insensitively). Using more descriptive names like sorted_elements or data_list is recommended.

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

Reasons

  1. Shadowing built-in types or using their names can lead to confusion and potential bugs
  2. Descriptive names like 'sorted_list' convey the prerequisite state for binary search
  3. Following naming standards prevents collision with Python's reserved keywords and types

Gaps

  1. In small algorithmic examples, generic names like 'List' are frequently used for simplicity
  2. The variable is local to the function, reducing the impact of shadowing built-ins

'''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: 90%

Global State for Iteration Counter

I notice we're using a global variable iterations to track the search count. This can lead to unexpected behavior if the function is called multiple times or in a multi-threaded environment, as the state is shared globally. It's generally safer to return the iteration count along with the result or use a class to encapsulate the state.

Reasons & Gaps

Reasons

  1. Global variables create hidden dependencies between different parts of the program
  2. Makes the function non-reentrant and difficult to test in isolation
  3. Concurrent calls to binarySearch will overwrite the shared iterations value

Gaps

  1. The script appears to be a standalone example where global state might be intentional for simplicity
  2. In a small script, thread safety is rarely a concern, but it remains a poor architectural pattern


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]
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: 85% View Citation

JAS - Just a suggestion
Vague Variable Name

The variable name ans is a common but non-standard abbreviation for 'answer'. Expanding it to result_index or target_position provides better semantic clarity.

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

Reasons

  1. Fully expressive names like 'result_index' describe exactly what the value represents
  2. Reducing abbreviations decreases the cognitive load required to understand the code logic
  3. Semantic naming helps distinguish between different types of return values in larger scripts

Gaps

  1. 'ans' is a widely understood abbreviation in competitive programming and math contexts
  2. The short scope of the script makes the purpose of 'ans' relatively clear to the reader

if(ans != -1):
print('Target found at position:',ans,'in',iterations,'iterations')
else:
print('Target not found')
21 changes: 21 additions & 0 deletions Test001/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 (Case Style)

In Python, function names should follow the snake_case convention. 'selectionSort' uses camelCase, which is non-standard for Python development.

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

Reasons

  1. PEP 8 specifies that function names should be lowercase with words separated by underscores
  2. Consistent naming conventions improve code maintainability across Python projects
  3. Standardizing to snake_case aligns the code with the broader Python ecosystem

Gaps

  1. The project might be following a legacy camelCase convention not visible in this diff
  2. Some developers coming from Java/C++ backgrounds may intentionally use camelCase in Python

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
Vague Variable Name

The variable name 'List' is a built-in type name in Python and is too generic. Using a more descriptive name like 'input_list' or 'elements' improves clarity.

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

Reasons

  1. Using 'List' as a variable name can be confused with the Python 'list' class or type hint
  2. Descriptive names like 'input_list' clearly communicate the variable's role in the algorithm
  3. Avoiding built-in names prevents potential shadowing issues and improves code semantics

Gaps

  1. 'List' is capitalized, avoiding a direct collision with the lowercase 'list' built-in
  2. In small utility functions, generic names are sometimes considered acceptable by some teams

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]
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 generic and shadows the concept of the built-in list type. A more descriptive name like 'unsorted_numbers' would be more appropriate.

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' does not describe the contents of the collection (e.g., numbers, scores)
  2. Capitalized variable names are typically reserved for Classes in Python (PascalCase)
  3. Descriptive naming helps distinguish between the input data and the sorting logic

Gaps

  1. In simple scripts, generic names for main data structures are common
  2. The context of a sorting example makes the purpose of the list relatively obvious

print('Sorted List:',selectionSort(List))
24 changes: 24 additions & 0 deletions Test001/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)
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%

JAS - Just a suggestion
Inaccurate Complexity Documentation

The docstring mentions that the best-case time complexity is O(n^2). However, for a standard bubble sort, while the average and worst cases are O(n^2), the best case (already sorted list) can be optimized to O(n) if a swap flag is used. Even without the flag, stating O(n^2) as the only 'Best' case is technically correct for this specific implementation but misleading as a general rule for the algorithm's potential.

Suggested change
# Best O(n^2); Average O(n^2); Worst O(n^2)
# Best O(n); Average O(n^2); Worst O(n^2)
Reasons & Gaps

Reasons

  1. Documentation should reflect the theoretical best-case performance of the algorithm
  2. Misleading complexity notes can lead to incorrect algorithm selection in performance-critical tasks
  3. Encourages the use of optimized variants that check if any swaps occurred during a pass

Gaps

  1. The current implementation actually performs O(n^2) comparisons even if the list is sorted
  2. Standard academic definitions often distinguish between optimized and non-optimized versions


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: 95% View Citation

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

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

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

Reasons

  1. PEP 8 style guide explicitly recommends snake_case for function and variable names
  2. Consistent naming conventions improve code maintainability and developer experience
  3. Adhering to language-specific standards reduces cognitive load for Python developers

Gaps

  1. Some legacy Python codebases or specific project styles may intentionally use camelCase for consistency with other languages
  2. The logic remains functional regardless of the naming convention used

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
Vague Variable Name

The variable name 'List' is a generic type name and should be more descriptive of the data it contains. Additionally, 'List' (capitalized) can be confused with the 'List' type hint from the typing module.

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

Reasons

  1. Using built-in type names as variable names can lead to shadowing and confusion
  2. Descriptive names like 'collection' or 'items' better reflect the variable's role in the algorithm
  3. Lowercase naming is preferred for variables in Python to distinguish them from classes

Gaps

  1. In a generic algorithm implementation, 'List' is technically accurate as it describes the expected data structure
  2. The scope is very small, making the purpose of the variable immediately obvious to the reader

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

if __name__ == '__main__':
List = [3, 4, 2, 6, 5, 7, 1, 9]
print('Sorted List:',bubbleSort(List))
25 changes: 25 additions & 0 deletions Test001/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: 90% View Citation

JAS - Just a suggestion
Function Naming Convention

In Python, function names should follow the snake_case convention. Additionally, 'List' is a built-in type name; using a more descriptive parameter name is recommended.

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

Reasons

  1. Python's PEP 8 standard requires function names to be in lowercase with underscores
  2. Using 'List' as a parameter name shadows the built-in list type in some contexts
  3. Consistent naming conventions improve maintainability for Python developers

Gaps

  1. The function name is technically descriptive of the algorithm being used
  2. camelCase is common in other languages, making this a stylistic rather than functional issue

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 Name

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

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

Reasons

  1. 'list' is a forbidden generic name according to the enterprise naming standard
  2. Shadowing built-in types can lead to confusion and potential runtime errors
  3. Descriptive names like 'elements' clarify what the collection contains

Gaps

  1. The variable is used as a parameter, where context is usually provided by the function name
  2. Python is case-sensitive, so 'List' (capitalized) technically differs from 'list'

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: 100%

Logical Error in Insertion Sort Inner Loop

I see what you're doing with the element swapping, but the current logic inside the inner loop is slightly off for a standard insertion sort. Specifically, the else block on line 18 incorrectly overwrites List[j + 1] with currentNumber during every step where the condition isn't met, and the swapping on line 16 is less efficient than the standard 'shift and insert' approach. In a proper insertion sort, we should shift elements greater than currentNumber to the right and then place currentNumber in its final sorted position once the loop finishes or breaks.

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


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
Forbidden Generic Name

The variable name 'List' is a forbidden generic name and shadows the Python built-in type. Use a more descriptive name like 'unsorted_numbers'.

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

Reasons

  1. 'list' is explicitly listed as a forbidden generic name in the coding standards
  2. Capitalized 'List' is often used for type hinting, creating semantic ambiguity
  3. Descriptive names improve code clarity when the list is passed to other functions

Gaps

  1. In a small script, the purpose of the variable is immediately obvious from the assignment
  2. The variable is local to the 'if name == "main"' block

print('Sorted List:',insertionSort(List))
Loading
Loading