Compare commits
1 Commits
aufgabe-oo
...
aufgabe-3
| Author | SHA1 | Date | |
|---|---|---|---|
| 7624caaf6c |
16
README.md
16
README.md
@ -1,14 +1,10 @@
|
||||
# Assignment 2 - Caesar Cipher
|
||||
# Assignment 3 - Adam & Eve Subclasses
|
||||
|
||||
This is my code for the OOP homework. I chose the Caesar Cipher Helper.
|
||||
This is my code for the Task 3 assignment using inheritance.
|
||||
|
||||
- **Link:** https://www.codewars.com/kata/526d42b6526963598d0004db
|
||||
- **Link:** https://www.codewars.com/kata/547274e24481cfc469000416
|
||||
|
||||
### How it works:
|
||||
- The `CaesarCipher` class takes a `shift` number.
|
||||
- `encode` changes text to uppercase and moves letters forward. It uses `% 26` so letters stay in the A-Z alphabet.
|
||||
- `decode` moves letters backward to fix the text.
|
||||
- Spaces and punctuation do not change.
|
||||
|
||||
### Tools:
|
||||
I set up black and ruff with pre-commit hooks. They check and fix my code format before every commit.
|
||||
- I created a base class called `Human`.
|
||||
- `Man` and `Woman` are subclasses that inherit everything from `Human`.
|
||||
- The `God` function creates and returns an array with the first man and woman.
|
||||
|
||||
@ -1,25 +1,12 @@
|
||||
class CaesarCipher:
|
||||
class Human:
|
||||
|
||||
def __init__(self, shift: int):
|
||||
self.shift = shift
|
||||
self.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
class Man(Human):
|
||||
pass
|
||||
|
||||
def encode(self, st: str) -> str:
|
||||
result = []
|
||||
for char in st.upper():
|
||||
if char in self.alphabet:
|
||||
new_index = (self.alphabet.index(char) + self.shift) % 26
|
||||
result.append(self.alphabet[new_index])
|
||||
else:
|
||||
result.append(char)
|
||||
return "".join(result)
|
||||
class Woman(Human):
|
||||
pass
|
||||
|
||||
def decode(self, st: str) -> str:
|
||||
result = []
|
||||
for char in st.upper():
|
||||
if char in self.alphabet:
|
||||
new_index = (self.alphabet.index(char) - self.shift) % 26
|
||||
result.append(self.alphabet[new_index])
|
||||
else:
|
||||
result.append(char)
|
||||
return "".join(result)
|
||||
def God():
|
||||
return [Man("Adam"), Woman("Eve")]
|
||||
Loading…
x
Reference in New Issue
Block a user