-
Notifications
You must be signed in to change notification settings - Fork 0
PR chenges #10
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
PR chenges #10
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,31 @@ | ||||||
| # 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. Single-Character Variable Name The variable name 'a' is non-descriptive. Using single-character names for business logic or user input makes the code harder to understand and maintain.
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. Single-Character Variable Name The variable name 'b' is non-descriptive. Descriptive names should be used to reflect the purpose of the data being stored.
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 | ||||||
| try: | ||||||
| print('Addition is:', int(a) + int(b)) | ||||||
| except ValueError: | ||||||
| print('Error: Please enter valid numeric values.') | ||||||
|
|
||||||
| 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. Single-Character Variable Name The variable name 'x' is non-descriptive. Using more meaningful names like 'global_count' or 'base_value' improves code clarity and maintainability.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
|
|
||||||
| def test(): | ||||||
|
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 'test' is a generic placeholder. Rename it to describe the specific action being performed, such as 'demonstrate_variable_scope'.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| #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. Single-Character Variable Name The variable name 'y' is ambiguous. A descriptive name such as 'local_offset' or 'adjustment_value' would better reflect its role in the function.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| x = 20 | ||||||
| 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. Non-Descriptive Variable Name The variable name
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
|
||||||||
| 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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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): | ||||||||||||||||
Sindhu1702013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| '''This function finds the factorial of the number passed as argument''' | ||||||||||||||||
| if number < 0: | ||||||||||||||||
| print('Invalid entry! Cannot find factorial of a negative number') | ||||||||||||||||
| if number == 0 or number == 1: | ||||||||||||||||
|
Comment on lines
+7
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. Infinite Recursion Risk on Negative Input I notice that when a negative number is entered, we print an error message but then proceed to evaluate the next
Suggested change
|
||||||||||||||||
| print("Hello") | ||||||||||||||||
| return 1 | ||||||||||||||||
| else: | ||||||||||||||||
| return number * factorial(number - 1) | ||||||||||||||||
|
|
||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||
| userInput = int(input('Enter the Number to find the factorial of: ')) | ||||||||||||||||
|
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. Variable Naming Convention (camelCase in Python) The variable name 'userInput' uses camelCase, which is not the standard naming convention for Python variables. Following PEP 8, variable names should use snake_case to maintain consistency with the rest of the Python ecosystem.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||
| print(factorial(userInput)) | ||||||||||||||||
| 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: ')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sindhu1702013 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern1(userInput) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern2(userInput) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern3(userInput) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern4(userInput) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern5(userInput) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pattern6(userInput): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| following is the another approach to solve pattern problems with reduced time complexity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| **** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ***** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| num = int(input('Enter number for pattern')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pattern = '*' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| string = pattern * num | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x = 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. Single-Character Variable Name The variable
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i in string: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x = x + 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(string[0:x]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+92
to
+112
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 Input and Logic Error in pattern6 I noticed that
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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): | ||||||
|
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 fuction helps to count the char frequency in the given string ''' | ||||||
| userInput = userInput.lower() #covert to lowercase | ||||||
| dict = {} | ||||||
|
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. |
||||||
| for char in userInput: | ||||||
| keys = dict.keys() | ||||||
|
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 char in keys: | ||||||
|
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 notice we're calling
Suggested change
|
||||||
| dict[char] += 1 | ||||||
| else: | ||||||
| dict[char] = 1 | ||||||
| return dict | ||||||
|
|
||||||
| if __name__ == '__main__': | ||||||
| userInput = str(input('Enter a string: ')) | ||||||
| print(charFrequency(userInput)) | ||||||
| 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): | ||||||
|
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. Boolean Function Naming Convention The function returns a boolean value but lacks a standard boolean prefix like 'is_' or 'has_'. Renaming it to 'is_prime' follows Python naming conventions for predicate functions.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| '''This function checks for prime number''' | ||||||
| isPrime = False | ||||||
| if number == 2: | ||||||
| print(number, 'is a Prime Number') | ||||||
| if number > 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. Logical Error: Redundant Output for Number 2 I notice that when the input is 2, the function prints that it is a prime number twice. This happens because the first
Suggested change
|
||||||
| for i in range(2, 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. Single-Character Variable Name While 'i' is common for loop counters, using a more descriptive name like 'divisor' or 'factor' can improve the clarity of the mathematical logic being performed.
Suggested change
Reasons & GapsReasons
Gaps
|
||||||
| 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: ')) | ||||||
|
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
|
||||||
| checkPrime(userInput) | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||
| class LoginSystem: | ||||||||||
|
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 Import for 'os' Module I notice we're using
Suggested change
|
||||||||||
| def __init__(self): | ||||||||||
| self.valid_email = os.getenv("VALID_EMAIL") | ||||||||||
|
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 see the addition of the
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 Import for 'os' Module I've noticed that
Suggested change
|
||||||||||
| self.valid_password = os.getenv("VALID_PASSWORD") | ||||||||||
|
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 see the addition of the |
||||||||||
| self.failed_attempts = 0 | ||||||||||
| self.locked = False | ||||||||||
|
|
||||||||||
| def login(self, email, password): | ||||||||||
|
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. Boolean-Returning Function Without Prefix The function
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| if self.locked: | ||||||||||
| return "Account is locked. Contact support." | ||||||||||
|
|
||||||||||
| if email == self.valid_email and password == self.valid_password: | ||||||||||
|
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 Constant Time Comparison Issue While this works for basic logic, using standard equality operators (
Suggested change
Reasons & GapsReasons
Gaps
|
||||||||||
| self.failed_attempts = 0 | ||||||||||
| return "Login Successful ✅" | ||||||||||
|
|
||||||||||
| else: | ||||||||||
| self.failed_attempts += 1 | ||||||||||
|
|
||||||||||
| if self.failed_attempts >= 3: | ||||||||||
| self.locked = True | ||||||||||
| return "Account locked due to 3 failed attempts ❌" | ||||||||||
|
|
||||||||||
| return f"Invalid credentials. Attempts left: {3 - self.failed_attempts}" | ||||||||||
|
|
||||||||||
| # ----- Testing the function ----- | ||||||||||
|
|
||||||||||
| app = LoginSystem() | ||||||||||
|
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(app.login("wrong@test.com", "123")) # Test case 1 | ||||||||||
| print(app.login("wrong@test.com", "123")) # Test case 2 | ||||||||||
| print(app.login("wrong@test.com", "123")) # Test case 3 (locks account) | ||||||||||
| print(app.login("user@test.com", "Password@123")) # Should fail because account is locked | ||||||||||
| print("TC4:", app.login("wrong@test.com", "123")) # This will now lock | ||||||||||
| print("TC5:", app.login("user@test.com", "Password@123")) # Locked account case | ||||||||||
| print("TC6:", app.login("user@test.com", "Password@123")) # Locked account case | ||||||||||
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 as per PEP 8. The current namejustPrintusescamelCase, which is non-standard for this language.Reasons & Gaps
Reasons
Gaps