Skip to content

Commit

Permalink
Added functions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
learnp committed Apr 8, 2016
1 parent e192b09 commit 1e4037c
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/py.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions 14_json_addressbook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
f = open("C:\\data\\book.txt","w+")
phone_book = {}
command = ""
while command != 'exit':
command = input('Enter a command(options: new,get,save): ')
if command == "new":
name = input('Enter name of the person')
p = input('Phone number: ')
a = input('Address: ')
phone_book[name] = {'phone': p, 'address': a}
elif command == 'get':
name = input('Enter name of the person')
if name in phone_book:
print(phone_book[name])
else:
print('person not found in address book')
elif command == 'save':
f.write(json.dumps(phone_book))
11 changes: 11 additions & 0 deletions 16_exception.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
x=input("Enter number1: ")
y=input("Enter number2: ")
try:
z = int(x) / int(y)
except ZeroDivisionError as e:
print('Division by zero exception')
z = None
except TypeError as e:
print('Type error exception')
z = None
print("Division is: ", z)
21 changes: 21 additions & 0 deletions 17_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Human:
def __init__(self, n, o):
self.name = n
self.occupation = o

def do_work(self):
if self.occupation == "tennis player":
print(self.name, "plays tennis")
elif self.occupation == "actor":
print(self.name, "shoots film")

def speaks(self):
print(self.name, "says how are you?")

tom = Human("tom cruise","actor")
tom.do_work()
tom.speaks()

maria = Human("maria sharapova","tennis player")
maria.do_work()
maria.speaks()
28 changes: 28 additions & 0 deletions 18_inheritance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Vehicle:
def general_usage(self):
print("general use: transporation")

class Car(Vehicle):
def __init__(self):
print("I'm car")
self.wheels = 4
self.has_roof = True

def specific_usage(self):
self.general_usage()
print("specific use: commute to work, vacation with family")

class MotorCycle(Vehicle):
def __init__(self):
print("I'm motor cycle")
self.wheels = 2
self.has_roof = False

def specific_usage(self):
self.general_usage()
print("specific use: road trip, racing")

c = Car()
m = MotorCycle()

print(issubclass(Car,MotorCycle))
16 changes: 16 additions & 0 deletions address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
book = {}
book['tom'] = {
'name': 'tom',
'address': '1 red street, NY',
'phone': 98989898
}
book['bob'] = {
'name': 'bob',
'address': '1 green street, NY',
'phone': 23424234
}

import json
s=json.dumps(book)
with open("c://data//book.txt","w") as f:
f.write(s)
8 changes: 8 additions & 0 deletions area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def calculate_area(base, height):
print("__name__: ",__name__)
return 1/2*(base*height)

if __name__ == "__main__":
print("I am in area.py")
a=calculate_area(10, 20)
print("area: ",a)
3 changes: 3 additions & 0 deletions caller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import area
print("I am in caller.py")
area.calculate_area(5,10)
6 changes: 6 additions & 0 deletions myprogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import sys
sys.path.append("C:\Code")
import functions as f
area = f.calculate_square_area(10)
area = f.calculate_triangle_area(5,10)
print(area)
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def sum(a,b):
return a+b

def sum(a,b):
return str(a)+str(b)+"***"

print(sum("a","b"))

0 comments on commit 1e4037c

Please sign in to comment.