Aufgabe3 : oop lösungen #3
3
README.md
Normal file
3
README.md
Normal file
@ -0,0 +1,3 @@
|
||||
#Aufgabe2 :
|
||||
**Codewars Username: ** hamzaola31-sketch**
|
||||
**Kata URL:**https://www.codewars.com/kata/54fe05c4762e2e3047000add**
|
||||
13
codewars/Aufgabe2.py
Normal file
13
codewars/Aufgabe2.py
Normal file
@ -0,0 +1,13 @@
|
||||
class Ship:
|
||||
def __init__(self, draft, crew):
|
||||
# Initialisierung der Schiff-Attribute: Tiefgang (draft) und Besatzung (crew)
|
||||
self.draft = draft
|
||||
self.crew = crew
|
||||
|
||||
def is_worth_it(self):
|
||||
# Berechnet, ob das Schiff beutenswert ist.
|
||||
# Jedes Besatzungsmitglied erhöht den Tiefgang um 1,5 Einheiten.
|
||||
# Ein Schiff ist lohnenswert, wenn der verbleibende Tiefgang nach Abzug
|
||||
# des Gewichts der Besatzung mehr als 20 Einheiten beträgt.
|
||||
return (self.draft - (self.crew * 1.5)) > 20
|
||||
|
||||
12
codewars/Interactive Dictionary.py
Normal file
12
codewars/Interactive Dictionary.py
Normal file
@ -0,0 +1,12 @@
|
||||
class Dictionary:
|
||||
def __init__(self):
|
||||
self.words = {}
|
||||
|
||||
def newentry(self, word, definition):
|
||||
self.words[word] = definition
|
||||
|
||||
def look(self, key):
|
||||
if key in self.words:
|
||||
return self.words[key]
|
||||
else:
|
||||
return f"Can't find entry for {key}"
|
||||
10
codewars/adam_and_eve.py
Normal file
10
codewars/adam_and_eve.py
Normal file
@ -0,0 +1,10 @@
|
||||
class Human:
|
||||
pass
|
||||
class Man(Human):
|
||||
pass
|
||||
class Woman(Human):
|
||||
pass
|
||||
def God():
|
||||
adam=Man()
|
||||
eve=Woman()
|
||||
return [adam,eve]
|
||||
28
codewars/banking_system.py
Normal file
28
codewars/banking_system.py
Normal file
@ -0,0 +1,28 @@
|
||||
class User:
|
||||
def __init__(self, name, balance, checking_account):
|
||||
self.name = name
|
||||
self.balance = balance
|
||||
self.checking_account = checking_account
|
||||
|
||||
def withdraw(self, amount):
|
||||
if amount > self.balance:
|
||||
raise ValueError("Not enough money")
|
||||
|
||||
self.balance -= amount
|
||||
return f"{self.name} has {self.balance}."
|
||||
|
||||
def add_cash(self, amount):
|
||||
self.balance += amount
|
||||
return f"{self.name} has {self.balance}."
|
||||
|
||||
def check(self, other_user, amount):
|
||||
if not other_user.checking_account:
|
||||
raise ValueError("User has no checking account")
|
||||
|
||||
if other_user.balance < amount:
|
||||
raise ValueError("Not enough money")
|
||||
|
||||
other_user.balance -= amount
|
||||
self.balance += amount
|
||||
|
||||
return f"{self.name} has {self.balance} and {other_user.name} has {other_user.balance}."
|
||||
15
codewars/building blocks.py
Normal file
15
codewars/building blocks.py
Normal file
@ -0,0 +1,15 @@
|
||||
class Block:
|
||||
def __init__(self, dims):
|
||||
self.width = dims[0]
|
||||
self.length = dims[1]
|
||||
self.height = dims[2]
|
||||
def get_width(self):
|
||||
return self.width
|
||||
def get_length(self):
|
||||
return self.length
|
||||
def get_height(self):
|
||||
return self.height
|
||||
def get_volume(self):
|
||||
return self.width * self.length * self.height
|
||||
def get_surface_area(self):
|
||||
return 2 * (self.width * self.length + self.width * self.height + self.length * self.height)
|
||||
4
codewars/classy extenstion.py
Normal file
4
codewars/classy extenstion.py
Normal file
@ -0,0 +1,4 @@
|
||||
from preloaded import Animal
|
||||
class Cat(Animal):
|
||||
def speak(self):
|
||||
return f"{self.name}: Meows."
|
||||
12
codewars/guess_the_number.py
Normal file
12
codewars/guess_the_number.py
Normal file
@ -0,0 +1,12 @@
|
||||
class Guesser:
|
||||
def __init__(self, number, lives):
|
||||
self.number = number
|
||||
self.lives = lives
|
||||
|
||||
def guess(self,n):
|
||||
if self.lives <=0:
|
||||
raise Exception("Omae wa mo shindeiru")
|
||||
if n== self.number:
|
||||
return True
|
||||
self.lives -=1
|
||||
return False
|
||||
17
codewars/thinkful-object drills.py
Normal file
17
codewars/thinkful-object drills.py
Normal file
@ -0,0 +1,17 @@
|
||||
class Vector:
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def add(self, other_vector):
|
||||
new_x = self.x + other_vector.x
|
||||
new_y = self.y + other_vector.y
|
||||
|
||||
return Vector(new_x, new_y)
|
||||
|
||||
|
||||
def subtract(self, other_vector):
|
||||
new_x = self.x - other_vector.x
|
||||
new_y = self.y - other_vector.y
|
||||
|
||||
return Vector(new_x, new_y)
|
||||
@ -3,3 +3,4 @@ def even_or_odd(number):
|
||||
return "Even"
|
||||
else:
|
||||
return "Odd"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user