Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Programs/P01_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
def justPrint(text):
'''This function prints the text passed as argument to this function'''
print(text)
a=input("Enter a number: ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 100% View Citation

Non-Descriptive Variable Name

The variable name 'a' is a single character, which lacks descriptive context. Use a more meaningful name like 'first_number' to improve code readability and maintainability.

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

b=input("Enter another number: ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 100% View Citation

Non-Descriptive Variable Name

The variable name 'b' is a single character. Renaming it to 'second_number' would make the code more self-documenting and easier for other developers to understand.

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

base_value = 10
increment_value=20
difference = increment_value - base_value
Expand All @@ -12,10 +14,11 @@ def justPrint(text):
floor_division = increment_value // base_value # // -> integer division

print("Floor Division:", floor_division)
print("Difference is:", increment_value - base_value)
# print("Difference is:", increment_value - base_value)
print("Divide value is:", divide_value)
print("Multiply value is:", multiply_value)
print("Modulus:", increment_value % base_value ) # % -> remainder
print('Addition is:', int(a) + int(b))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning Confidence Score: 95%

Using int() on input() without validation can crash the script if the user enters non-numeric data. We should use a try-except block to handle ValueError and ensure the program continues.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 100% View Citation

Variable Naming Consistency

Update the variable names 'a' and 'b' to 'first_number' and 'second_number' to maintain consistency with the updated definitions and improve code clarity.

Suggested change
print('Addition is:', int(a) + int(b))
print('Addition is:', int(first_number) + int(second_number))


if __name__ == '__main__':
justPrint('Hello Sindhuja')
Expand Down
8 changes: 4 additions & 4 deletions Programs/P02_VariableScope.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

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

x = 'Global x'
x = 80 # Global x
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 85% View Citation

Single-Character Variable Name

The variable name 'x' is non-descriptive and violates naming standards for global variables. Use a more meaningful name like 'global_limit' to improve code clarity.

Suggested change
x = 80 # Global x
global_limit = 80


def test():
#global x
y = 'Local y'
x = 'Local x'
print(x +', '+ y) #prints 'Local x' and 'Local y'
y = 100 # Local y
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 85% View Citation

Single-Character Variable Name

The variable name 'y' is non-descriptive. Using single-character names (outside of loops) makes the code harder to maintain. Consider using a more descriptive name like 'y_value'.

Suggested change
y = 100 # Local y
y_value = 100

x = 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Confidence Score: 85% View Citation

Single-Character Variable Name

The variable name 'x' is non-descriptive. Use a more meaningful name like 'x_value' to improve code clarity and maintainability.

Suggested change
x = 20
x_value = 20

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

if __name__ == '__main__':
test()
Expand Down
1 change: 1 addition & 0 deletions Programs/P03_ListsOperations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Author: OMKAR PATHAK
#This program gives examples about various list operations
# User story id : Prod - PYTH-003

#Syntax: list[start: end: step]

Expand Down
48 changes: 48 additions & 0 deletions Programs/listoperations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Author: OMKAR PATHAK
#This program gives examples about various list operations
# User story id : Prod - PYTH-003

#Syntax: list[start: end: step]

myList = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAS Confidence Score: 85% View Citation

JAS - Just a suggestion
Variable Naming Refinement

The variable name 'myList' uses a generic suffix and camelCase, which is non-standard for Python. Renaming it to 'numbers' or 'integer_list' using snake_case would improve clarity and PEP 8 compliance.

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

Reasons

  1. Python naming conventions (PEP 8) recommend snake_case for variable names
  2. The suffix 'List' is redundant as the data structure is evident from the assignment
  3. 'numbers' provides better semantic meaning than the generic 'myList'

Gaps

  1. The variable is functional and common in educational scripts
  2. The script context is a simple demonstration where generic names are often tolerated

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

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

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

#To find the index of a particular element
print('Index of element \'6\':',myList.index(6)) #returns index of element '6'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning Confidence Score: 100%

Potential ValueError in List Indexing

I noticed we're calling .index(6) on the list. While this works for the initial list, if the element '6' is ever removed or not present due to previous operations (like the pop() on line 29), this will raise a ValueError and crash the script. It's safer to check if the element exists before fetching its index.

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


#To sort the list
myList.sort()

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

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

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

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

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

#To reverse a list
myList.reverse()
print('Reversed list:',myList)
Loading