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 Programs/Test/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):
'''This function prints the text passed as argument to this function'''
print(text)
a=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: 85%

JAS - Just a suggestion

Single-Character Variable Name

The variable name 'a' is non-descriptive. Use a name that reflects the purpose of the input, such as 'first_number' or 'input_value_a', to improve code readability.

Suggested change
a=input("Enter a number: ")
first_number = input("Enter a number: ")

b=input("Enter another 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%

JAS - Just a suggestion

Single-Character Variable Name

The variable name 'b' is non-descriptive. A more expressive name like 'second_number' would clarify the variable's role in the addition logic.

Suggested change
b=input("Enter another number: ")
second_number = input("Enter another number: ")

base_value = 10
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.

Warning Confidence Score: 100%

Potential Runtime Error: Unhandled Input Type

I notice we're directly casting the inputs a and b to integers. If a user enters something that isn't a number (like a string or special character), the program will crash with a ValueError. It's usually safer to wrap these in a try-except block or validate the input first to ensure the program handles non-numeric input gracefully.

Suggested change
print('Addition is:', int(a) + int(b))
try:
print('Addition is:', int(a) + int(b))
except ValueError:
print('Error: Please enter valid numeric values for addition.')


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


16 changes: 16 additions & 0 deletions Programs/Test/P02_VariableScope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Author: OMKAR PATHAK
#This programs shows the rules for variable scope

# LEGB Rule: Local, Enclosing, Global, Built-in

x = 80 # Global x
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

Single-Character Variable Name

The variable name 'x' is non-descriptive. Using single-character names for global state reduces code readability and maintainability. Consider using a more descriptive name like 'global_count' or 'base_value'.

Suggested change
x = 80 # Global x
global_value = 80 # Global value


def test():
#global x
y = 100 # Local y
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

Single-Character Variable Name

The variable name 'y' is a single character, which is discouraged for local variables that are not loop counters. A more descriptive name like 'local_offset' or 'increment_value' would improve clarity.

Suggested change
y = 100 # Local y
local_value = 100 # Local value

x = 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%

Shadowing Global Variable

JAS - Just a suggestion
I notice we're defining x = 20 inside the test() function. This creates a local variable that shadows the global x = 80. While this demonstrates local scope, it can lead to confusion if the intention was to modify the global variable. If we want to update the global x, we should use the global keyword.

Suggested change
x = 20
global x
x = 20

print(x + y) #prints 'Local x' and 'Local y'

if __name__ == '__main__':
test()
print(x) #prints 'Global x'
48 changes: 48 additions & 0 deletions Programs/Test/P03_ListsOperations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Author: OMKAR PATHAK
#This program gives examples about various list operations
# User story id : Prod - PYTH-003

#Syntax: list[start: end: step]

myList = [1, 2, 3, 4, 5, 6, 7, 8, 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%

JAS - Just a suggestion

Non-Descriptive Variable Name

The variable name 'myList' is generic and does not describe the content or purpose of the data. Using a more descriptive name like 'numbers' or 'integer_list' improves code maintainability.

Suggested change
myList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
numbers =

#index 0 1 2 3 4 5 6 7 8
# -9 -8 -7 -6 -5 -4 -3 -2 -1

#List Slicing
print('Original List:',myList)
print('First Element:',myList[0]) #Prints the first element of the list or 0th element of the list
print('Element at 2nd Index position:',myList[2]) #Prints the 2nd element of the list
print('Elements from 0th Index to 4th Index:',myList[0: 5]) #Prints elements of the list from 0th index to 4th index. IT DOESN'T INCLUDE THE LAST INDEX
print('Element at -7th Index:',myList[-7]) #Prints the -7th or 3rd element of the list

#To append an element to a list
myList.append(10)
print('Append:',myList)

#To find the index of a particular element
print('Index of element \'6\':',myList.index(6)) #returns index of element '6'
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%

Potential ValueError in List Index Lookup

JAS - Just a suggestion
I notice we're using myList.index(6) to find the position of an element. While this works for the example, it's worth noting that index() will raise a ValueError if the element isn't in the list. To make this more robust, we could check if the element exists first or wrap it in a try-except block.

Suggested change
print('Index of element \'6\':',myList.index(6)) #returns index of element '6'
if 6 in myList:
print('Index of element \'6\':',myList.index(6))


#To sort the list
myList.sort()

#To pop last element
print('Poped Element:',myList.pop())

#To remove a particular element from the lsit BY NAME
myList.remove(6)
print('After removing \'6\':',myList)

#To insert an element at a specified Index
myList.insert(5, 6)
print('Inserting \'6\' at 5th index:',myList)

#To count number of occurences of a element in the list
print('No of Occurences of \'1\':',myList.count(1))

#To extend a list that is insert multiple elemets at once at the end of the list
myList.extend([11,0])
print('Extending list:',myList)

#To reverse a list
myList.reverse()
print('Reversed list:',myList)
17 changes: 17 additions & 0 deletions Programs/Test/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):
'''This function finds the factorial of the number passed as argument'''
if number < 0:
print('Invalid entry! Cannot find factorial of a negative number')
Comment on lines +7 to +8
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%

Incorrect Logic for Negative Input

I notice that when a negative number is entered, we print an error message but then continue execution into the next if block and the else block. This will lead to a RecursionError because the function will keep calling itself with increasingly negative numbers. We should return early or use an elif structure to prevent this.

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

if number == 0 or number == 1:
print("Hello")
Comment on lines +9 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.

JAS Confidence Score: 100%

Unnecessary Debug Print in Base Case

JAS - Just a suggestion
I see a print("Hello") statement inside the base case of the factorial function. This will clutter the output every time the recursion finishes. Unless this was intended for debugging, we should remove it to keep the function's output clean and focused on the result.

Suggested change
if number == 0 or number == 1:
print("Hello")
if number == 0 or number == 1:

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

JAS - Just a suggestion

Variable Naming Violation

The variable name 'userInput' uses camelCase, which violates Python's snake_case convention. Renaming it to 'user_input' improves consistency with PEP 8 and the rest of the codebase.

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: '))

print(factorial(userInput))
112 changes: 112 additions & 0 deletions Programs/Test/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):
#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: 85%

JAS - Just a suggestion

Non-Standard Variable Naming

The variable name 'userInput' uses camelCase, which is non-standard for Python. Additionally, 'userInput' is somewhat generic; a more descriptive name like 'pattern_level' would improve clarity.

Suggested change
userInput = int(input('Enter the level: '))
pattern_level = int(input('Enter the level: '))

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

def pattern6(userInput):
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: 88%

Unreachable and Redundant Nested Function

I noticed that pattern6 is defined inside the if __name__ == '__main__': block but is never actually called. Additionally, it asks for input() again inside the function, which is redundant since userInput is already passed as an argument. We should move this function to the top level and clean up the input logic to make it usable.

Reasons & Gaps

Reasons

  1. Nested function definition inside a conditional block makes it unreachable
  2. Redundant input handling inside a function that already receives parameters
  3. Inefficient string slicing in a loop for pattern generation

Gaps

  1. The developer might have intended to call this function later in the script or in a different module
  2. The nested definition might be a temporary placeholder for a refactoring effort

'''
following is the another approach to solve pattern problems with reduced time complexity

for

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

num = int(input('Enter number for pattern'))
pattern = '*'
string = pattern * num
x = 0

for i in string:
x = x + 1
print(string[0:x])
18 changes: 18 additions & 0 deletions Programs/Test/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: 92%

JAS - Just a suggestion

Function Naming Convention

In Python, function names should follow the snake_case convention. Additionally, the name 'charFrequency' could be more descriptive to clearly indicate that it calculates character frequencies.

Suggested change
def charFrequency(userInput):
def get_character_frequency(user_input):

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

JAS - Just a suggestion

Generic Variable Name

Using 'dict' as a variable name is discouraged because it shadows the built-in Python dict type and is too generic. Use a more descriptive name like 'frequency_map' or 'char_counts'.

Suggested change
dict = {}
char_counts = {}

for char in userInput:
keys = dict.keys()
if char in keys:
Comment on lines +9 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.

JAS Confidence Score: 100%

Inefficient Dictionary Key Lookup

JAS - Just a suggestion
I notice we're calling dict.keys() inside the loop. In Python, you can check for membership directly in the dictionary itself, which is much more efficient and readable. This avoids creating a view object on every single iteration of the loop.

Suggested change
keys = dict.keys()
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 Programs/Test/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: 88%

JAS - Just a suggestion

Boolean-Returning Function Without Prefix

The function 'checkPrime' returns a boolean value (via the 'isPrime' flag logic) but lacks a standard boolean prefix like 'is_' or 'has_'. Renaming it to 'is_prime' improves clarity and follows Pythonic conventions.

Suggested change
def checkPrime(number):
def is_prime(number):

'''This function checks for prime number'''
isPrime = False
if number == 2:
print(number, 'is a Prime Number')
if number > 1:
Comment on lines +7 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: 100%

Redundant and Conflicting Prime Logic

I notice that when the input is 2, the code prints that it is a prime number twice. This happens because the first if block handles 2, but the second if number > 1 block also executes and triggers the loop logic. We should use an elif or structure the conditions to avoid this double printing and redundant check.

Suggested change
if number == 2:
print(number, 'is a Prime Number')
if number > 1:
if number == 2:
print(number, 'is a Prime Number')
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: 85%

JAS - Just a suggestion

Non-Standard Abbreviation and Casing

The variable 'userInput' uses camelCase, which is non-standard for Python variables. Additionally, while 'userInput' is understandable, 'input_number' would be more expressive in the context of a prime number checker.

Suggested change
userInput = int(input('Enter a number to check: '))
input_number = int(input('Enter a number to check: '))

checkPrime(userInput)
45 changes: 45 additions & 0 deletions Programs/Test/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()
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.

Critical Confidence Score: 100%

Stopwatch Logic Error: Start Time Reset

I notice that the starttime is being reset inside the while True loop every time the user presses ENTER. This means the stopwatch effectively restarts on every input instead of measuring the time from the first start to the stop command (Ctrl+C). We should move the start time initialization outside the loop to correctly measure the total elapsed time.

Suggested change
try:
input() #For ENTER
starttime = time.time()
print('Started')
input() # Press ENTER to start
starttime = time.time()
print('Started')
try:
while True:
time.sleep(0.1) # Wait for Ctrl+C

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

Non-Standard Abbreviation

The variable name 'val' is a non-standard abbreviation. Expanding it to 'user_input' or 'input_value' would improve code clarity and maintainability.

Suggested change
val=input() #For ENTER
user_input = 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 Programs/Test/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')
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.

Critical Confidence Score: 45%

Single-Character Variable Name

The variable 'i' is used as a loop counter. While often acceptable, using a more descriptive name like 'index' or 'directory_index' can improve clarity in scripts performing file operations.

Suggested change
for i in range(1,10):
for index in range(1, 10):

print('Here i is',i)
os.rename('newDir' + str(i),'newDir' + str(i + 1))
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%

Directory Renaming Logic Error

I noticed a logic issue in the loop. We're creating 'newDir1' outside the loop, but then trying to rename 'newDir1' to 'newDir2', then 'newDir2' to 'newDir3', and so on. However, the loop starts at i=1 and goes to 9. After the first iteration, 'newDir1' no longer exists, but the code doesn't create any new directories to rename in subsequent steps. This will cause a FileNotFoundError on the second iteration. We should probably create the directory inside the loop or adjust the renaming logic.

Suggested change
os.rename('newDir' + str(i),'newDir' + str(i + 1))
if os.path.exists('newDir' + str(i)):
os.rename('newDir' + str(i), 'newDir' + str(i + 1))

time.sleep(2)
24 changes: 24 additions & 0 deletions Programs/Test/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():
''' 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 notice a small discrepancy between the game's instructions and the actual logic. The prompt tells users to guess between 0 and 20, but random.randint(0, 21) actually includes 21 as a possible secret number. This means a user following the instructions could never guess 21, even if it's the correct answer! Let's adjust the range to (0, 20) to match the prompt.

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

JAS - Just a suggestion

Variable Naming Improvement

The variable name 'randomNumber' uses camelCase, which is inconsistent with Python's snake_case convention. Renaming it to 'random_number' improves consistency and readability.

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

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%

Missing Input Validation for Non-Integers

The current implementation uses int(input(...)) directly. If a user accidentally types a letter or a special character instead of a number, the program will crash with a ValueError. To make the game more robust, we should wrap the input in a try-except block to handle invalid inputs gracefully without stopping the game.

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('Invalid input! 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 Programs/Test/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%

JAS - Just a suggestion

Function Naming Convention

In Python, function names should follow the snake_case convention. Rename sequentialSearch to sequential_search to align with PEP 8 and project standards.

Suggested change
def sequentialSearch(target, List):
def sequential_search(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%

JAS - Just a suggestion

Forbidden Generic Name

The variable name List is a forbidden generic name and shadows the built-in list type. Use a more descriptive name like numbers or search_list.

Suggested change
def sequentialSearch(target, List):
def sequential_search(target, search_list):

'''This function returns the position of the target if found else returns -1'''
position = 0
global iterations
iterations = 0
Comment on lines +7 to +8
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%

Unnecessary Global Variable Usage

I notice we're using a global variable iterations to track the search progress. While this works for a simple script, it can lead to side effects if the function is called multiple times or used in a larger application. It's generally safer to return the iteration count along with the result or handle it locally within the function scope.

Reasons & Gaps

Reasons

  1. Using global variables makes functions harder to test and reuse
  2. Global state prevents thread safety and concurrent execution
  3. Returning multiple values is a better Pythonic pattern for state tracking

Gaps

  1. The script is intended as a simple example where global state might be acceptable for educational purposes
  2. Thread safety is not a concern for this specific standalone execution context

while position < len(List):
iterations += 1
if target == List[position]:
return position
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: 88%

JAS - Just a suggestion

Vague Generic Name

The variable name ans is a non-standard abbreviation for 'answer'. Use a more descriptive name like result_index or target_position to improve semantic clarity.

Suggested change
ans = sequentialSearch(target, List)
target_position = sequential_search(target, search_list)

if ans != -1:
print('Target found at position:',ans,'in',iterations,'iterations')
else:
print('Target not found in the list')
Loading
Loading