Skip to content

Commit 3f004af

Browse files
updted
1 parent 6bb518e commit 3f004af

5 files changed

Lines changed: 74 additions & 4 deletions

File tree

44-encryption-program/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
print(f"key: {key}")
1818

1919
# ENCRYPTION
20-
plain_text = input("Enter a message to encrypt")
20+
plain_text = input("Enter a message to encrypt: ")
2121
cipher_text = ""
2222

2323
for letter in plain_text:
24-
index = chars.index(letter)
25-
cipher_text += key[index]
24+
index_of_letter = chars.index(letter)
25+
cipher_text += key[index_of_letter]
2626

2727
print(f'original message: {plain_text}')
2828
print(f'encryption message: {cipher_text}')

46-python-oop/car-blueprint.png

1.55 MB
Loading

46-python-oop/cars.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Python Object Oriented Programming
2+
# object = A "bundle" of related attributes and methods(functions)
3+
# Ex. phone, cup, book, car, dog
4+
# You need a "class" to create many objects of the same type
5+
6+
# class = (blueprint) used to design the structure and layout of an object
7+
8+
# method = A function that is defined inside a class
9+
10+
# DUNDER means double underscore __init__ = constructor method
11+
12+
# create a class
13+
class Car:
14+
# attributes
15+
def __init__(self, make, model, year, color): # constructor method
16+
self.make = make
17+
self.model = model
18+
self.year = year
19+
self.color = color
20+
self.mileage = 0
21+
self.for_sale = False
22+
23+
# define methods
24+
def drive(self):
25+
print(f"The {self.make} is driving.")
26+
27+
def stop(self):
28+
print(f"The {self.make} has stopped.")
29+
30+
def left_turn(self):
31+
print(f"The {self.make} is turning left.")
32+
def right_turn(self):
33+
print(f"The {self.make} is turning right.")
34+
def park(self):
35+
print(f"The {self.make} is parked.")
36+
37+
# # create objects (instances) of the Car class
38+
# camry_car = Car("Toyota", "Camry", 2020, "Blue")
39+
# civic_car = Car("Honda", "Civic", 2019, "Red")
40+
41+
# # access attributes
42+
# print(camry_car.make) # Output: Toyota
43+
# print(civic_car.model) # Output: Civic
44+
# print(camry_car.year) # Output: 2020
45+
# # call methods
46+
# camry_car.drive(camry_car.make)
47+
# civic_car.park(civic_car.make)
48+
# camry_car.left_turn(camry_car.make)
49+
# civic_car.right_turn(civic_car.make)
50+
# camry_car.stop(camry_car.make)
51+
# civic_car.drive(civic_car.make)

46-python-oop/main.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

46-python-oop/script1.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# first import the Car class from cars module
2+
3+
from cars import Car
4+
5+
6+
# create objects (instances) of the Car class
7+
camry_car = Car("Toyota", "Camry", 2020, "Blue")
8+
civic_car = Car("Honda", "Civic", 2019, "Red")
9+
10+
# # access attributes
11+
print(camry_car.make) # Output: Toyota
12+
print(civic_car.model) # Output: Civic
13+
print(camry_car.year) # Output: 2020
14+
# # call methods
15+
camry_car.drive()
16+
civic_car.park()
17+
camry_car.left_turn()
18+
civic_car.right_turn()
19+
camry_car.stop()
20+
civic_car.drive()

0 commit comments

Comments
 (0)