-
-
Save datavudeja/5422cdb6a32c54f92f3ee183dd830824 to your computer and use it in GitHub Desktop.
24 Feb 2018
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
class Car(): | |
def __init__(self, make, model, year): | |
self.make = make | |
self.model = model | |
self.year = year | |
self.odometer_reading = 0 | |
def get_descriptive_name(self): | |
long_name = str(self.year) + ' ' + self.make + ' ' + self.model | |
return long_name.title() | |
def read_odometer(self): | |
print("This car has " + str(self.odometer_reading) + " miles on it.") | |
my_new_car = Car('audi', 'a4', 2016) | |
print(my_new_car.get_descriptive_name()) | |
my_new_car.odometer_reading = 23 | |
print(my_new_car.read_odometer()) | |
''' | |
with open('alice.txt') as file_object: | |
contents = file_object.read() | |
print(contents[10:100]) | |
''' | |
with open('test.txt', 'w') as test_write: | |
write = test_write.write("I love Python") | |
with open('test.txt') as test_read: | |
read = test_read.read() | |
print(read) | |
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero'] | |
def times_tables(): | |
lst = [] | |
for i in range(10): | |
for j in range (10): | |
lst.append(i*j) | |
return lst | |
times_tables() == [j*i for i in range(10) for j in range(10)] | |
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
def build_person(first_name, last_name, age=''): | |
person = {'first': first_name, 'last': last_name} | |
if age: | |
person['age'] = age | |
return person | |
musician = build_person('jimi', 'hendrix', '27') | |
artists = build_person('nasir', 'asad') | |
print(musician) | |
print(artists) | |
## | |
def make_album(artist_name, artist_title, number_of_track=''): | |
album = {'name': artist_name, 'title': artist_title} | |
return album | |
album1 = make_album('Navaid', 'Best song') | |
for k,v in album1.items(): | |
print(k,v) | |
## | |
def greet_users(x): | |
y=x*2 | |
print(y) | |
return y | |
x=10 | |
z= greet_users(x) | |
print(x) | |
print(z) |
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
import math | |
import numpy as np | |
from scipy import stats | |
test_ex = [5, 9, 12, 2, 4, 18, 11] | |
print("Mean: ", np.mean(test_ex)) | |
print("Median: ", np.median(test_ex)) | |
mode = stats.mode(test_ex) | |
print("Mode: The modal value is {} with a count of {}".format(mode.mode[0], mode.count[0])) | |
print("Variance: ", np.var(test_ex)) | |
print("Standard Deviation: ", np.std(test_ex)) | |
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
class Dog(): | |
def __init__(self, name, age): | |
self.name = name | |
self.age = age | |
def sit(self): | |
print(self.name.title() + "is now sitting") | |
def roll_over(self): | |
print(self.name.title() + "roll over.") | |
my_dog = Dog("willie", 6) | |
print("My dog name is " + my_dog.name + " and dog is " + str(my_dog.age) + " years old") | |
class retaurant(): | |
def __init__(self, restaurant_name, cuisine_type): | |
self.restaurant_name = restaurant_name | |
self.cuisine_type = cuisine_type | |
def open_rastaurant(self): | |
print(self.restaurant_name + "is open.") | |
res_name = retaurant("PC", "5 stars") |
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
class retaurant(): | |
def __init__(self, restaurant_name, cuisine_type): | |
self.restaurant_name = restaurant_name | |
self.cuisine_type = cuisine_type | |
self.number_served = 0 | |
def open_rastaurant(self): | |
print(self.restaurant_name + "is open.") | |
def set_number_served(self): | |
print(self.number_served) | |
def increment_number_served(self): | |
print(self.number_served) | |
res_name = retaurant("PC", "5 stars") | |
#print(res_name.restaurant_name.title(), res_name.cuisine_type) | |
res_name.number_served = 10 | |
res_name.set_number_served() | |
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