-
Notifications
You must be signed in to change notification settings - Fork 0
Sindhu python #8
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
Changes from all commits
2f2150b
b4d632c
5f686e5
1aa50ef
0b0ca83
1696203
dde091c
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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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: ") | ||||||||||||||||
| 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. |
||||||||||||||||
| base_value = 10 | ||||||||||||||||
| increment_value=20 | ||||||||||||||||
| difference = increment_value - base_value | ||||||||||||||||
|
|
@@ -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)) | ||||||||||||||||
|
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. 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. 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
|
||||||||||||||||
|
|
||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||
| justPrint('Hello Sindhuja') | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,13 @@ | |
|
|
||
| # LEGB Rule: Local, Enclosing, Global, Built-in | ||
|
|
||
| x = 'Global x' | ||
| 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. |
||
|
|
||
| def test(): | ||
| #global x | ||
| y = 'Local y' | ||
| x = 'Local x' | ||
| print(x +', '+ y) #prints 'Local x' and 'Local y' | ||
| 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. |
||
| 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. |
||
| print(x + y) #prints 'Local x' and 'Local y' | ||
|
|
||
| if __name__ == '__main__': | ||
| test() | ||
|
|
||
| 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 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
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' | ||||||||
|
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 Indexing I noticed we're calling
Suggested change
|
||||||||
|
|
||||||||
| #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) | ||||||||
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.
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.