-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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)) |
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) |
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() |
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)) |
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) |
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) |
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) |
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) |
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")) |