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:
|
### How it works:
|
||||||
- The `CaesarCipher` class takes a `shift` number.
|
- I created a base class called `Human`.
|
||||||
- `encode` changes text to uppercase and moves letters forward. It uses `% 26` so letters stay in the A-Z alphabet.
|
- `Man` and `Woman` are subclasses that inherit everything from `Human`.
|
||||||
- `decode` moves letters backward to fix the text.
|
- The `God` function creates and returns an array with the first man and woman.
|
||||||
- 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.
|
|
||||||
|
|||||||
@ -1,25 +1,12 @@
|
|||||||
class CaesarCipher:
|
class Human:
|
||||||
|
|
||||||
def __init__(self, shift: int):
|
def __init__(self, name: str):
|
||||||
self.shift = shift
|
self.name = name
|
||||||
self.alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
class Man(Human):
|
||||||
|
pass
|
||||||
|
|
||||||
def encode(self, st: str) -> str:
|
class Woman(Human):
|
||||||
result = []
|
pass
|
||||||
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 decode(self, st: str) -> str:
|
def God():
|
||||||
result = []
|
return [Man("Adam"), Woman("Eve")]
|
||||||
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)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user