Compare commits
No commits in common. "main" and "uebung1" have entirely different histories.
@ -1,14 +0,0 @@
|
||||
# Abgabe - Counting Duplicates Aufgabe von Codewars
|
||||
# Link dazu: https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1
|
||||
# Leart Ramushi
|
||||
|
||||
|
||||
def duplicate_count(text):
|
||||
lower_text = text.lower()
|
||||
letter_set = set()
|
||||
|
||||
for i in range(len(lower_text)):
|
||||
if lower_text.count(lower_text[i]) > 1:
|
||||
letter_set.add(lower_text[i])
|
||||
|
||||
return len(letter_set)
|
||||
@ -1,43 +0,0 @@
|
||||
# Abgabe - PaginationHelper Aufgabe von Codewars
|
||||
# Link dazu: https://www.codewars.com/kata/515bb423de843ea99400000a
|
||||
# Leart Ramushi
|
||||
|
||||
# TODO: complete this class
|
||||
import math
|
||||
|
||||
|
||||
class PaginationHelper:
|
||||
|
||||
# The constructor takes in an array of items and an integer indicating
|
||||
# how many items fit within a single page
|
||||
def __init__(self, collection, items_per_page):
|
||||
self.collection = collection
|
||||
self.items_per_page = items_per_page
|
||||
|
||||
# returns the number of items within the entire collection
|
||||
def item_count(self):
|
||||
return len(self.collection)
|
||||
|
||||
# returns the number of pages
|
||||
def page_count(self):
|
||||
return math.ceil(len(self.collection) / self.items_per_page)
|
||||
|
||||
# returns the number of items on the given page. page_index is zero based
|
||||
# this method should return -1 for page_index values that are out of range
|
||||
def page_item_count(self, page_index):
|
||||
if page_index < 0 or page_index >= self.page_count():
|
||||
return -1
|
||||
if page_index == self.page_count() - 1:
|
||||
rest = len(self.collection) % self.items_per_page
|
||||
if rest == 0:
|
||||
return self.items_per_page
|
||||
else:
|
||||
return rest
|
||||
return self.items_per_page
|
||||
|
||||
# determines what page an item at the given index is on. Zero based indexes.
|
||||
# this method should return -1 for item_index values that are out of range
|
||||
def page_index(self, item_index):
|
||||
if item_index < 0 or item_index >= len(self.collection):
|
||||
return -1
|
||||
return item_index // self.items_per_page
|
||||
@ -1,51 +0,0 @@
|
||||
# Abgabe - Vigenère Cipher Helper
|
||||
# Link dazu: https://www.codewars.com/kata/52d1bd3694d26f8d6e0000d3
|
||||
# Leart Ramushi
|
||||
|
||||
|
||||
class VigenereCipher(object):
|
||||
def __init__(self, key, alphabet):
|
||||
self.key = key
|
||||
self.alphabet = alphabet
|
||||
self.alp_len = len(alphabet)
|
||||
pass
|
||||
|
||||
def encode(self, text):
|
||||
result = ""
|
||||
key_pos = 0
|
||||
print(text)
|
||||
|
||||
for pos in range(len(text)):
|
||||
currrent_char = text[pos]
|
||||
if currrent_char in self.alphabet:
|
||||
key_char = self.key[key_pos % len(self.key)]
|
||||
# print(currrent_char, " - ", key_char)
|
||||
text_index = self.alphabet.index(currrent_char)
|
||||
key_index = self.alphabet.index(key_char)
|
||||
# print(text_index, " - ", key_index)
|
||||
update_index = (text_index + key_index) % len(self.alphabet)
|
||||
result += self.alphabet[update_index]
|
||||
else:
|
||||
result += currrent_char
|
||||
key_pos += 1
|
||||
print(result)
|
||||
return result
|
||||
|
||||
def decode(self, text):
|
||||
result = ""
|
||||
key_pos = 0
|
||||
|
||||
for pos in range(len(text)):
|
||||
currrent_char = text[pos]
|
||||
if currrent_char in self.alphabet:
|
||||
key_char = self.key[key_pos % len(self.key)]
|
||||
# print(currrent_char, " - ", key_char)
|
||||
text_index = self.alphabet.index(currrent_char)
|
||||
key_index = self.alphabet.index(key_char)
|
||||
# print(text_index, " - ", key_index)
|
||||
update_index = (text_index - key_index) % len(self.alphabet)
|
||||
result += self.alphabet[update_index]
|
||||
else:
|
||||
result += currrent_char
|
||||
key_pos += 1
|
||||
return result
|
||||
@ -1,23 +0,0 @@
|
||||
class Konto:
|
||||
def __init__(self, inhaber, saldo):
|
||||
self.inhaber = inhaber
|
||||
self.saldo = saldo
|
||||
|
||||
def einzahlen(self, betrag):
|
||||
self.saldo += betrag
|
||||
|
||||
def abheben(self, betrag):
|
||||
if betrag <= self.saldo:
|
||||
self.saldo -= betrag
|
||||
else:
|
||||
print("Leider nicht genug Geld auf dem Konto")
|
||||
|
||||
def __repr__(self):
|
||||
return f"Konto(inhaber='{self.inhaber}', saldo={self.saldo})"
|
||||
|
||||
def __str__(self):
|
||||
return f"Konto von {self.inhaber} mit einem Saldo von {self.saldo} Euro"
|
||||
|
||||
|
||||
k = Konto("Max Mustermann", 100)
|
||||
print(str(k))
|
||||
Loading…
x
Reference in New Issue
Block a user