-
Notifications
You must be signed in to change notification settings - Fork 0
Sindhu python #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sindhu python #16
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||
| #Author: OMKAR PATHAK | ||||||||||
| #This program calculates the LCM of the two numbers entered by the user | ||||||||||
|
|
||||||||||
| def LCM(number1, number2): | ||||||||||
| '''This function calculates LCM of two numbers inputed by the user''' | ||||||||||
| maximum = max(number1, number2) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Division by Zero Risk I noticed that if a user enters '0' as one of the numbers, the program will crash with a
Suggested change
|
||||||||||
| i = maximum | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
| 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: ')) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
| userInput2 = int(input('Enter second number: ')) | ||||||||||
| print('LCM of {} and {} is {}'.format( userInput1, userInput2, LCM(userInput1, userInput2))) | ||||||||||
| 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): | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||
| '''This function calculates the decimal equivalent to given binary number''' | ||||||||||||||||||||
| binary1 = binary | ||||||||||||||||||||
| decimal, i, n = 0, 0, 0 | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||
| while(binary != 0): | ||||||||||||||||||||
| dec = binary % 10 | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||
| decimal = decimal + dec * pow(2, i) | ||||||||||||||||||||
|
Comment on lines
+8
to
+10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
|
||||||||||||||||||||
| 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: ')) | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable 'userInput' uses camelCase, which is inconsistent with Python's snake_case convention for variables.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||
| binaryToDecimal(userInput) | ||||||||||||||||||||
| 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): | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion Python function names should follow
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||
| '''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: ')) | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, variable names should follow the
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||
| decimalToBinary(userInput) | ||||||||||||||||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||||
| print() | ||||||||||||||||
| 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): | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||
| '''This function checks the string for palindrome''' | ||||||||||||
| revString = string[::-1] | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||
| 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: ')) | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name 'userInput' uses camelCase. In Python, the standard convention for variables is snake_case. Consider renaming it to 'user_input'.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| palindrome(userInput) | ||||||||||||
| 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): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||
| '''This function checks whether the entered number is greater than those in the list''' | ||||||
| original = [1,2,3,4,5] | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||
| 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') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inaccurate Logic in Failure Message I noticed a small logic issue in the
Suggested change
|
||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| userInput = int(input('Enter the number to check: ')) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion Python variables should use snake_case instead of camelCase. 'user_input' is the preferred naming convention for local variables in Python.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| checkGreater(userInput) | ||||||
| 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(): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||
| '''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') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential IndexError for Command-Line Arguments I notice we're accessing
Suggested change
|
||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| arguments() | ||||||
| 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): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, function names should follow the
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| '''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: ")) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion I noticed we're using
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion Variable names in Python should use
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| count = countVowels(userInput) | ||||||||||
| print('Vowel Count: ',count) | ||||||||||
| 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): | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||
| '''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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Runtime Error on Non-Numeric Input I noticed that we're calling
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||
| return even, odd | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||||||
| userInput = input("Enter the numbers (space separated) to check: ") | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||
| userInput = list(userInput.split()) | ||||||||||||||||||||||||||
| even, odd = evenOdd(userInput) | ||||||||||||||||||||||||||
| print('Even Nos: ', ','.join(even), '\n', 'Odd Nos: ', ','.join(odd)) | ||||||||||||||||||||||||||
| 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): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||
| ''' This function creates a log file if any error is reported ''' | ||||||
| logging.basicConfig(filename = 'P18-logfile.txt', level = logging.INFO) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ineffective Logging Configuration I notice that Reasons & GapsReasons
Gaps
|
||||||
| 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: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bare Exception Clause I see we're using a bare
Suggested change
|
||||||
| print('Please enter a valid integer') | ||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| try: | ||||||
| userInput = int(input('Enter a number: ')) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion Python variables should follow the
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| log(userInput) | ||||||
| except: | ||||||
| print('Please enter a valid integer') | ||||||
| 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() | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||
| print('Started') | ||||||||||||||||||
|
Comment on lines
+8
to
+11
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential UnboundLocalError on Interrupt I notice that if a user presses
Suggested change
|
||||||||||||||||||
| except KeyboardInterrupt: | ||||||||||||||||||
| print('Stopped') | ||||||||||||||||||
| endtime = time.time() | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||
| 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 | ||||||||||||||||||
|
|
||||||||||||||||||
| """ | ||||||||||||||||||
|
|
||||||||||||||||||
| 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') | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential Crash: Directory Already Exists I notice we're calling
Suggested change
|
||||||||||||||||||||||
| for i in range(1,10): | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||
| print('Here i is',i) | ||||||||||||||||||||||
| os.rename('newDir' + str(i),'newDir' + str(i + 1)) | ||||||||||||||||||||||
|
Comment on lines
+9
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logic Error: Renaming Non-Existent Directories In the loop, we're trying to rename
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||
| time.sleep(2) | ||||||||||||||||||||||
| 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(): | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The function name
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||
| ''' This function guesses the randomnly generated number ''' | ||||||||||||||||||
| randomNumber = random.randint(0, 21) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, variable names should follow the
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||
| count = 0 | ||||||||||||||||||
|
|
||||||||||||||||||
| while True: | ||||||||||||||||||
| count += 1 | ||||||||||||||||||
| number = int(input('Enter the number between 0 to 20: ')) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||
| 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() | ||||||||||||||||||
| 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): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The function name 'sequentialSearch' uses camelCase, which violates the Python snake_case convention (PEP 8).
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| '''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 | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global State for Iteration Tracking I notice we're using a global variable
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| position += 1 | ||||||||||
| return -1 | ||||||||||
|
|
||||||||||
| if __name__ == '__main__': | ||||||||||
| List = [1, 2, 3, 4, 5, 6, 7, 8] | ||||||||||
| target = 3 | ||||||||||
| ans = sequentialSearch(target, List) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name 'ans' is a non-standard abbreviation for 'answer'. Expanding it to 'result' or 'position' improves semantic clarity.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| if ans != -1: | ||||||||||
| print('Target found at position:',ans,'in',iterations,'iterations') | ||||||||||
| else: | ||||||||||
| print('Target not found in the list') | ||||||||||
| 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): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, function names should follow the
Suggested change
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| '''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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Global State for Iteration Counter I notice we're using a global variable Reasons & GapsReasons
Gaps
|
||||||||||
|
|
||||||||||
| 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) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion The variable name
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| if(ans != -1): | ||||||||||
| print('Target found at position:',ans,'in',iterations,'iterations') | ||||||||||
| else: | ||||||||||
| print('Target not found') | ||||||||||
| 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): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, function names should follow the
Suggested change
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
| 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] | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
| print('Sorted List:',selectionSort(List)) | ||||||||||
| 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) | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
|
|
||||||||||
| def bubbleSort(List): | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, function names should follow the
Suggested change
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||
| 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)) | ||||||||||
| 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): | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion In Python, function names should follow the
Suggested change
Reasons & GapsReasons
Gaps
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return List | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||||
| List = [3, 4, 2, 6, 5, 7, 1, 9] | ||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JAS - Just a suggestion 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
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||
| print('Sorted List:',insertionSort(List)) | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'.
Reasons & Gaps
Reasons
Gaps