Skip to content

Commit

Permalink
lecture 10
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwanglulu committed Apr 26, 2023
1 parent 266d6af commit f15b966
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 58 deletions.
72 changes: 39 additions & 33 deletions lecture10/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ <h2 style="color: white">10.1 OOP Basics</h2>
</div>
</div>
</section>
<section>
<section data-background-image="../bg.png">
<ul>
<li class="fragment">
<p>Working with Classes and Instances</p>
</li>
</ul>
<div class='div-c'>
<div class="fragment">
<pre><code class="language-Python" data-line-numbers data-trim contenteditable>
class Car():
Expand All @@ -159,16 +160,18 @@ <h2 style="color: white">10.1 OOP Basics</h2>
self.odometer_reading = 0

def get_descriptive_name(self):
long_name="{} {} {}".format(self.year,\
self.make,self.model)
long_name=f"{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.")
print(f"This car has\
{self.odometer_reading}\
miles on it.")
</code></pre>
</div>
</div>
<div class='div-d'>
<div class="fragment">
<pre><code class="language-Python" data-line-numbers data-trim contenteditable>
my_new_car = Car('audi', 'a4', 2016)
Expand All @@ -181,7 +184,7 @@ <h2 style="color: white">10.1 OOP Basics</h2>
2016 Audi A4
This car has 0 miles on it.
</code></pre>
</div>
</div></div>
</section>
<section data-background-image="../bg.png">
<div class='div-c'>
Expand All @@ -200,9 +203,9 @@ <h2 style="color: white">10.1 OOP Basics</h2>
self.odometer_reading = 0

def read_odometer(self):
print("This car has "
+ str(self.odometer_reading)
+ " miles on it.")
print(f"This car has\
{self.odometer_reading}\
miles on it.")
</code></pre>
</div>
</div>
Expand Down Expand Up @@ -243,9 +246,9 @@ <h2 style="color: white">10.1 OOP Basics</h2>
self.odometer_reading = 0

def read_odometer(self):
print("This car has "
+ str(self.odometer_reading)
+ " miles on it.")
print(f"This car has\
{self.odometer_reading}\
miles on it.")

def update_odometer(self, mileage):
self.odometer_reading = mileage
Expand Down Expand Up @@ -295,15 +298,16 @@ <h2 style="color: white">10.1 OOP Basics</h2>
self.odometer_reading = 0

def read_odometer(self):
print("This car has "
+ str(self.odometer_reading)
+ " miles on it.")
print(f"This car has\
{self.odometer_reading}\
miles on it.")

def update_odometer(self, mileage):
self.odometer_reading = mileage

def increment_odometer(self, miles):
self.odometer_reading += miles
self.odometer_reading \
= self.odometer_reading + miles
</code></pre>
</div>
</div>
Expand Down Expand Up @@ -369,9 +373,10 @@ <h2 style="color: white">10.2 Inheritance, Polymorphism</h2>
self.model = model
self.year = year
self.odometer_reading = 0

def get_descriptive_name(self):
long_name="{} {} {}".format(self.year,\
self.make,self.model)
long_name=f"{self.year} {self.make}\
{self.model}"
return long_name.title()
</code></pre>
</div>
Expand Down Expand Up @@ -413,9 +418,10 @@ <h5>Polymorphism</h5>
self.model = model
self.year = year
self.odometer_reading = 0

def get_descriptive_name(self):
long_name="{} {} {}".format(self.year,\
self.make,self.model)
long_name=f"{self.year} {self.make}\
{self.model}"
return long_name.title()
</code></pre>
</div>
Expand All @@ -427,9 +433,9 @@ <h5>Polymorphism</h5>
def __init__(self, make, model, year):
super().__init__(make, model, year)
self.battery_size = 70

def describe_battery(self):
print(str(self.battery_size)
+"-kWh battery.")
print(f"{self.battery_size}-kWh battery.")
</code></pre>
</div>
<div class="fragment">
Expand Down Expand Up @@ -462,9 +468,10 @@ <h5>Polymorphism</h5>
self.model = model
self.year = year
self.odometer_reading = 0

def get_descriptive_name(self):
long_name="{} {} {}".format(self.year,\
self.make,self.model)
long_name=f"{self.year} {self.make}\
{self.model}"
return long_name.title()
</code></pre>
</div>
Expand All @@ -478,11 +485,10 @@ <h5>Polymorphism</h5>
self.battery_size = 70

def describe_battery(self):
print(str(self.battery_size)
+"-kWh battery.")
print(f"{self.battery_size}-kWh battery.")

def get_descriptive_name(self):
long_name = str(self.year)+' '+self.make
long_name=f"{self.year} {self.make}"
return long_name.title()
</code></pre>
</div>
Expand Down Expand Up @@ -709,14 +715,14 @@ <h2 style="color: white">10.3 Special Methods, Import Class</h2>
</ul>
<div class="fragment">
<pre><code class="language-Python" data-line-numbers data-trim contenteditable>
stuff = list()
stuff = []
stuff.append('python')
stuff.append('chuck')
stuff.sort()

print (stuff[0])
print (stuff.__getitem__(0))
print (list.__getitem__(stuff,0))
print(stuff[0])
print(stuff.__getitem__(0))
print(list.__getitem__(stuff,0))
</code></pre>
</div>
<div class="fragment">
Expand All @@ -743,7 +749,7 @@ <h2 style="color: white">10.3 Special Methods, Import Class</h2>
self.name = name
self.age = age
def __str__(self):
return "Dog's name is {}.".format(self.name)
return f"Dog's name is {self.name}."


my_dog = Dog('willie', 6)
Expand Down
21 changes: 3 additions & 18 deletions lecture10/test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
class Dog():
def __init__(self, name, age):
self.name = name
self.age = age

def sit(self):
print(f"{self.name.title()} \
is now sitting.")

def roll_over(self):
print(f"{self.name.title()} \
rolled over!")


my_dog = Dog('willie', 6)

print(my_dog.name.title())
print(str(my_dog.age) + " years old")
class Dog(list):
pass

3 changes: 3 additions & 0 deletions lecture9/programming.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I love programming.
I love creating new games.
I love
15 changes: 8 additions & 7 deletions lecture9/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
filename = 'alice.txt'
try:
with open(filename) as f_obj:
contents = f_obj.read()
except FileNotFoundError:
msg = f"Sorry, the file {filename} does not exist."
print(msg)
filename = 'programming.txt'
with open(filename, 'w') as file_object:
file_object.write("I love programming.\n")
file_object.write("I love creating new games.\n")


with open(filename, 'a') as file_object:
file_object.write("I love")

1 comment on commit f15b966

@vercel
Copy link

@vercel vercel bot commented on f15b966 Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.