-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PadamSethia/PadamSethia-patch-1
Added sum_classes.py
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# This example uses python classes for addition | ||
|
||
class Numbers(object): | ||
def __init__(self): | ||
self.sum = 0 | ||
|
||
def add(self,x): | ||
# Addtion funciton | ||
self.sum += x | ||
|
||
def total(self): | ||
# Returns the total of the sum | ||
return self.sum | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
# Prints 12 on the terminal when the file is run, | ||
# you can even use input() to get numbers from | ||
# users. | ||
|
||
add = Numbers() | ||
add.add(5) | ||
add.add(7) | ||
y = add.total() | ||
print("Total Sum : " , y) |