-
Notifications
You must be signed in to change notification settings - Fork 0
Added changes #14
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
Added changes #14
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,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: ") | ||||||||||||
|
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 'a' is non-descriptive. Use a name that reflects the purpose of the data, such as 'first_number' or 'input_value_a'.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| b=input("Enter another 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 name 'b' is non-descriptive. Use a name like 'second_number' to improve code clarity.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| 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)) | ||||||||||||
|
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: Unhandled Non-Integer Input I noticed that we're directly casting the user inputs
Suggested change
|
||||||||||||
|
|
||||||||||||
| if __name__ == '__main__': | ||||||||||||
| justPrint('Hello Sindhuja') | ||||||||||||
| justPrint('Hello Sindhuja') | ||||||||||||
| justPrint('Hello Sindhuja') | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| 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 | ||||||
|
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 'x' is non-descriptive. Using single-letter names for global variables or business logic makes the code harder to maintain and understand.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
|
|
||||||
| def test(): | ||||||
| #global x | ||||||
| y = 100 # Local y | ||||||
|
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 'y' is a single character. Unless used as a coordinate or in a simple loop, variables should have descriptive names that reflect their intent.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| x = 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. JAS - Just a suggestion The variable name 'x' is non-descriptive. Using the same single-letter name as a global variable leads to shadowing and potential logic confusion.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| print(x + y) #prints 'Local x' and 'Local y' | ||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| test() | ||||||
| print(x) #prints 'Global x' | ||||||
| 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] | ||||||||
|
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 'myList' uses a generic type suffix and is not descriptive of the data it contains. In Python, it is better to name variables based on their purpose (e.g., 'numbers' or 'integer_list') rather than just the data type.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||
| #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' | ||||||||
|
|
||||||||
| #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) | ||||||||
|
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 ValueError in List Removal I noticed we're calling
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||
| 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) | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -102,7 +102,7 @@ def pattern6(userInput): | |||||||||
| ***** | ||||||||||
| ''' | ||||||||||
|
|
||||||||||
| num = userInput | ||||||||||
| num = int(input('Enter number for pattern')) | ||||||||||
|
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. Functional Logic Error: Redundant Parameter and Modularity Break I notice we've changed
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 'num' is a common but non-standard abbreviation. Expanding it to 'number' or 'row_count' would improve code clarity and align with expressive naming standards.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| pattern = '*' | ||||||||||
| string = pattern * num | ||||||||||
| x = 0 | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||
| #Author: OMKAR PATHAK | ||||||||||||||||||||||||||||
| #This program calculates the fibonacci series till the n-th term | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def fibonacci(number): | ||||||||||||||||||||||||||||
| '''This function calculates the fibonacci series till the n-th term''' | ||||||||||||||||||||||||||||
| if number <= 1: | ||||||||||||||||||||||||||||
| return number | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| return (fibonacci(number - 1) + fibonacci(number - 2)) | ||||||||||||||||||||||||||||
|
Comment on lines
+4
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. Exponential Time Complexity in Recursion The recursive implementation of Fibonacci has O(2^n) time complexity. For larger values of
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| def fibonacci_without_recursion(number): | ||||||||||||||||||||||||||||
| if number == 0: return 0 | ||||||||||||||||||||||||||||
| fibonacci0, fibonacci1 = 0, 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. JAS - Just a suggestion The variable names
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||||
| for i in range(2, number + 1): | ||||||||||||||||||||||||||||
| fibonacci1, fibonacci0 = fibonacci0 + fibonacci1, fibonacci1 | ||||||||||||||||||||||||||||
| return fibonacci1 | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||||||||
| userInput = int(input('Enter the number upto which you wish to calculate fibonnaci series: ')) | ||||||||||||||||||||||||||||
|
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-Integer Input 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 The variable
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||||
| for i in range(userInput + 1): | ||||||||||||||||||||||||||||
| print(fibonacci(i),end=' ') | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| print("\nUsing LOOP:") | ||||||||||||||||||||||||||||
| print(fibonacci_without_recursion(userInput)) | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||||
| #Author: OMKAR PATHAK | ||||||||||||
| #This program calculates the factorial of a given number | ||||||||||||
|
|
||||||||||||
| def factorial(number): | ||||||||||||
| '''This function calculates the factorial of a number''' | ||||||||||||
| if number == 1 or number == 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. Recursion Depth Risk and Negative Input Handling The
Suggested change
|
||||||||||||
| return 1 | ||||||||||||
| else: | ||||||||||||
| return number * factorial(number - 1) | ||||||||||||
|
|
||||||||||||
| def factorial_without_recursion(number): | ||||||||||||
| fact = 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. JAS - Just a suggestion The variable name 'fact' is an abbreviation for 'factorial'. Expanding it to 'factorial_result' or 'result' improves code readability and follows the enterprise naming standard.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| while(number > 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. Infinite Loop Risk in Iterative Method Similar to the recursive version, the
Suggested change
|
||||||||||||
| fact = fact * number | ||||||||||||
| number = number - 1 | ||||||||||||
| print('Factorial of', number,'is: ') | ||||||||||||
|
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. Incorrect Output in Iterative Factorial In the
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| print(fact) | ||||||||||||
|
|
||||||||||||
| if __name__ == '__main__': | ||||||||||||
| userInput = int(input('Enter the number to find its factorial: ')) | ||||||||||||
|
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. Renaming it to 'user_input' aligns with PEP 8 and project standards.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||
| print('Factorial of', userInput, 'is:', factorial(userInput)) | ||||||||||||
| factorial_without_recursion(userInput) | ||||||||||||
| 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): | ||||||||||
|
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 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. Zero Division Error in LCM Calculation 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 logic rather than a simple loop counter. Using a more descriptive name like
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
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 violates Python's snake_case convention. Additionally, if this function were intended to validate or return a status, it would require a boolean prefix.
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 used outside of a loop definition. Using more descriptive names like 'exponent' or 'counter' improves 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 'dec' is a non-standard abbreviation. Expanding it to 'remainder' or 'last_digit' makes the logic more explicit.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||
| 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: ')) | ||||||||||||||||
|
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 not the standard convention for Python variables. Use snake_case ('user_input') instead.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||
| binaryToDecimal(userInput) | ||||||||||||||||
|
Comment on lines
+16
to
+17
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 Input Validation for Binary Format I notice we're taking an integer input and assuming it only contains 0s and 1s. If a user enters a number like '123', the logic will still run and produce a mathematically 'correct' but logically invalid decimal result for a non-binary input. We should validate that the input only contains binary digits to ensure functional correctness.
Suggested change
|
||||||||||||||||
| 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 non-descriptive. Using a more explicit name like 'decimal_number' improves code readability and aligns with Python's snake_case naming conventions.
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 In Python, function names should follow the
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 The variable 'userInput' uses
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: Unhandled Non-Integer Input I notice we're using
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 return a result (or print a status) should ideally use a boolean prefix like 'is_' or 'check_'. Consider renaming to 'is_palindrome'.
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 is case-sensitive. This means 'Radar' would be flagged as 'not a palindrome' because 'R' doesn't match 'r'. Usually, palindrome checks should be case-insensitive to be more functional for users. We can fix this by converting the string to lowercase before comparing.
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 a non-standard abbreviation 'rev' and follows camelCase, which is not idiomatic for Python variables. Use snake_case and descriptive names like '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 'userInput' uses camelCase. In Python, variables should follow the snake_case convention (e.g., 'user_input') to align with PEP 8 standards.
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 comparison logic) but lacks a standard boolean prefix such as
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] | ||||||
| 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. JAS - Just a suggestion The current logic correctly identifies if a number is not greater than the maximum element, but the print message is misleading. If the number is equal to the maximum element, it is not 'less than' the list; it's simply not greater than all elements. We should update the message to accurately reflect the comparison result.
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 The variable
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 noun and does not clearly describe the action being performed. Renaming it to a verb-based name like 'print_command_line_arguments' would better communicate 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. Misleading Error Message I notice that the error message says 'Give only two arguments', but the code actually expects exactly two arguments in addition to the script name (total of 3 elements in
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 The function name 'countVowels' uses camelCase which is non-standard for Python. Additionally, if this function were intended to return a boolean, it would require a prefix like 'is_'. However, since it returns a count, it should follow snake_case convention.
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 The variable 'userInput' uses camelCase. In Python, variables should follow the snake_case naming convention to maintain consistency with the language's style guide.
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 In Python, function names should follow the
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: | ||||||
|
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 Non-Numeric Input I noticed that we're calling
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| even.append(number) | ||||||
| else: | ||||||
| odd.append(number) | ||||||
| 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
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
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. Hardcoded Log File Path I noticed the log file path is hardcoded to Let's externalize this configuration. The best practice is to either log to
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. Redundant Logging Configuration Calling 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 Except Clause 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 In Python, variable names 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
+7
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. Logic Error: Start Time Reset I notice that
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 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
This file was deleted.
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 (Case Style)
In Python, function names should follow the
snake_caseconvention. Additionally, 'justPrint' is slightly vague; a name likeprint_messageordisplay_textwould be more descriptive.Reasons & Gaps
Reasons
Gaps