init()
parent
50e720c81a
commit
a319de72cc
2
s1_a4.py
2
s1_a4.py
|
@ -5,6 +5,6 @@ if __name__ == "__main__":
|
||||||
approximate_value = 0
|
approximate_value = 0
|
||||||
divider = 1
|
divider = 1
|
||||||
while series_value != round(approximate_value, 6):
|
while series_value != round(approximate_value, 6):
|
||||||
approximate_value += 1/divider**2
|
approximate_value = 1/divider**2
|
||||||
divider += 1
|
divider += 1
|
||||||
print("The sum equals", series_value, "after adding", divider-1, "reciprocal square numbers.")
|
print("The sum equals", series_value, "after adding", divider-1, "reciprocal square numbers.")
|
||||||
|
|
|
@ -3,10 +3,10 @@ class SparseMatrix:
|
||||||
self.__matrix = dict()
|
self.__matrix = dict()
|
||||||
|
|
||||||
def save(self, matrix) -> None:
|
def save(self, matrix) -> None:
|
||||||
for row in range(len(matrix)):
|
for row, values in enumerate(matrix):
|
||||||
for col in range(len(matrix[row])):
|
for col, value in enumerate(values):
|
||||||
if matrix[row][col] != 0:
|
if value != 0:
|
||||||
self.__matrix[(row, col)] = matrix[row][col]
|
self.__matrix[(row, col)] = value
|
||||||
|
|
||||||
def get(self, row, col) -> int or None:
|
def get(self, row, col) -> int or None:
|
||||||
if self.__matrix[(row, col)]:
|
if self.__matrix[(row, col)]:
|
||||||
|
|
|
@ -5,8 +5,7 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# 5.4
|
# 5.4
|
||||||
def remove_duplicates(word: str):
|
def remove_duplicates(word: str):
|
||||||
result = "".join(sorted(set(word), key=word.index))
|
return "".join(sorted(set(word), key=word.index))
|
||||||
print(word, len(word), "\n", result, len(result))
|
|
||||||
remove_duplicates("Donaudampfschiffahrtsgesellschaftsstewardess")
|
remove_duplicates("Donaudampfschiffahrtsgesellschaftsstewardess")
|
||||||
|
|
||||||
# 5.5
|
# 5.5
|
||||||
|
@ -15,5 +14,4 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
# 5.6
|
# 5.6
|
||||||
def get_animal_sound(animal: str) -> str:
|
def get_animal_sound(animal: str) -> str:
|
||||||
animal_dictionary = {"Lion": "Growl", "Dog": "Bark", "Cat": "Meow"}
|
return {"Lion": "Growl", "Dog": "Bark", "Cat": "Meow"}.get(animal, "Not found.")
|
||||||
return animal_dictionary.get(animal, "Not found.")
|
|
||||||
|
|
Loading…
Reference in New Issue