Initialer Import der Synology Scripts
This commit is contained in:
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
# C++, Java: this
|
||||
|
||||
|
||||
class Animal:
|
||||
def __init__(self, weight, height):
|
||||
self.weight = weight
|
||||
self.height = height
|
||||
|
||||
def jump(self):
|
||||
print("Jump!")
|
||||
|
||||
|
||||
def main():
|
||||
dog = Animal(10, 0.8)
|
||||
print(dog.height)
|
||||
print(dog.weight)
|
||||
dog.jump()
|
||||
|
||||
cat = Animal(3, 0.3)
|
||||
print(cat.height)
|
||||
print(cat.weight)
|
||||
cat.jump()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,10 @@
|
||||
dct = {"Jan": 27, "Peter": 33}
|
||||
lst = [1, 2, 3]
|
||||
|
||||
|
||||
try:
|
||||
print(lst[3])
|
||||
except KeyError as e:
|
||||
print(e)
|
||||
except IndexError as e:
|
||||
print(e)
|
||||
@@ -0,0 +1,30 @@
|
||||
"""Exercise 4:
|
||||
1.)
|
||||
Write a function that takes an integer number "n" as an input.
|
||||
The function returns a list with all power of twos (2^n)
|
||||
from 0 to n-1. Use a list comprehension.
|
||||
2.)
|
||||
Write a function that takes the resulting list from 1.) as
|
||||
an input. Iterate over all values of the list and print
|
||||
the current index and the current value in each iteration.
|
||||
"""
|
||||
|
||||
|
||||
def exercise1(n):
|
||||
pass
|
||||
|
||||
|
||||
def exercise2(lst):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
n = 10
|
||||
lst = exercise1(n)
|
||||
print(lst)
|
||||
|
||||
exercise2(lst)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,30 @@
|
||||
"""Exercise 5:
|
||||
1.)
|
||||
Write a class Student that has the following member variables:
|
||||
- Name (String)
|
||||
- Lastname (String)
|
||||
- Age (Integer)
|
||||
- Id (Integer)
|
||||
2.)
|
||||
Write a method that prints the information about the student.
|
||||
E.g. Student('Jan', 'Schaffranek', 27, 1080133228459) will print:
|
||||
'Jan Schaffranek is 27 years old and has the id 1080133228459'
|
||||
"""
|
||||
|
||||
|
||||
class Student:
|
||||
pass
|
||||
|
||||
def print_student(self):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
oskar = Student("Oskar", "Oskarson", 29, 1080132254623)
|
||||
oskar.print_student()
|
||||
jan = Student("Jan", "Schaffranek", 28, 1080133228459)
|
||||
jan.print_student()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,14 @@
|
||||
input_filepath = "C:/Users/Jan/OneDrive/_Coding/UdemyPythonIntro/Chapter4_Intermediate/test.txt" # noqa: E501
|
||||
output_filepath = "C:/Users/Jan/OneDrive/_Coding/UdemyPythonIntro/Chapter4_Intermediate/test_out.txt" # noqa: E501
|
||||
|
||||
|
||||
with open(input_filepath) as file:
|
||||
content = file.readlines()
|
||||
|
||||
|
||||
print(content)
|
||||
content.append("Tom Tomerson\n")
|
||||
|
||||
|
||||
with open(output_filepath, "w") as file:
|
||||
file.writelines(content)
|
||||
@@ -0,0 +1,38 @@
|
||||
class Animal:
|
||||
def __init__(self, weight, height):
|
||||
self.weight = weight
|
||||
self.height = height
|
||||
|
||||
def print_data(self):
|
||||
print("Height: ", self.height)
|
||||
print("Weight: ", self.weight)
|
||||
|
||||
|
||||
class Dog(Animal):
|
||||
def __init__(self, weight, height):
|
||||
super().__init__(weight, height)
|
||||
|
||||
def bark(self):
|
||||
print("Bark!")
|
||||
|
||||
|
||||
class Cat(Animal):
|
||||
def __init__(self, weight, height):
|
||||
super().__init__(weight, height)
|
||||
|
||||
def meow(self):
|
||||
print("Meow!")
|
||||
|
||||
|
||||
def main():
|
||||
dog = Dog(10, 0.8)
|
||||
dog.print_data()
|
||||
dog.bark()
|
||||
|
||||
cat = Cat(3, 0.3)
|
||||
cat.print_data()
|
||||
cat.meow()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,31 @@
|
||||
# break, continue, pass, None
|
||||
|
||||
l1 = [1, 2, 3, 4, 5]
|
||||
|
||||
for val in l1:
|
||||
if val > 3:
|
||||
break
|
||||
print(val)
|
||||
|
||||
|
||||
print("")
|
||||
|
||||
|
||||
for val in l1:
|
||||
if val % 2 == 0:
|
||||
continue
|
||||
print(val)
|
||||
|
||||
|
||||
def print_list(l1):
|
||||
pass
|
||||
|
||||
|
||||
print_list(l1)
|
||||
|
||||
|
||||
print("")
|
||||
|
||||
|
||||
val1 = None
|
||||
print(val1)
|
||||
@@ -0,0 +1,15 @@
|
||||
list_a = []
|
||||
|
||||
for _i in range(100):
|
||||
list_a.append(5)
|
||||
|
||||
print(list_a)
|
||||
|
||||
# List comp
|
||||
list_b = [5 for i in range(100)]
|
||||
|
||||
print(list_b)
|
||||
|
||||
list_c = [i**2 for i in range(100)]
|
||||
|
||||
print(list_c)
|
||||
@@ -0,0 +1,19 @@
|
||||
list_a = list(range(10))
|
||||
|
||||
print(list_a)
|
||||
|
||||
list_b = [list_a[i] for i in range(3)]
|
||||
|
||||
print(list_b)
|
||||
|
||||
# List Slicing
|
||||
|
||||
# Start, Stop, Step
|
||||
list_c = list_a[0:3:1]
|
||||
|
||||
print(list_c)
|
||||
|
||||
list_c[0] = -100
|
||||
|
||||
print(list_a)
|
||||
print(list_c)
|
||||
@@ -0,0 +1,16 @@
|
||||
num_rows = 3
|
||||
num_cols = 2
|
||||
|
||||
matrix = [
|
||||
[(i * num_cols + j) + 1 for j in range(num_cols)] for i in range(num_rows)
|
||||
]
|
||||
|
||||
print(matrix)
|
||||
|
||||
matrix2 = [[0 for j in range(num_cols)] for i in range(num_rows)]
|
||||
|
||||
print(matrix2)
|
||||
|
||||
matrix2[0][0] = 1
|
||||
|
||||
print(matrix2)
|
||||
@@ -0,0 +1,12 @@
|
||||
# (3,)
|
||||
vector = [1, 2, 3]
|
||||
|
||||
print(vector)
|
||||
|
||||
# (3, 2)
|
||||
matrix = [[1, 2], [3, 4], [5, 6]]
|
||||
|
||||
print(matrix)
|
||||
|
||||
print(matrix[0])
|
||||
print(matrix[1][0])
|
||||
@@ -0,0 +1,15 @@
|
||||
l1 = ["a", "b", "a", "c"]
|
||||
print(l1)
|
||||
|
||||
|
||||
s1 = set(l1)
|
||||
print(s1)
|
||||
|
||||
|
||||
s2 = {"a", "d"}
|
||||
print(s2)
|
||||
|
||||
|
||||
print(s1.intersection(s2))
|
||||
print(s1.union(s2))
|
||||
print(s1.difference(s2))
|
||||
@@ -0,0 +1,31 @@
|
||||
"""Exercise 4:
|
||||
1.)
|
||||
Write a function that takes an integer number "n" as an input.
|
||||
The function returns a list with all power of twos (2^n)
|
||||
from 0 to n-1. Use a list comprehension.
|
||||
2.)
|
||||
Write a function that takes the resulting list from 1.) as
|
||||
an input. Iterate over all values of the list and print
|
||||
the current index and the current value in each iteration.
|
||||
"""
|
||||
|
||||
|
||||
def exercise1(n):
|
||||
return [2**i for i in range(n)]
|
||||
|
||||
|
||||
def exercise2(lst):
|
||||
for idx, val in enumerate(lst):
|
||||
print(idx, val)
|
||||
|
||||
|
||||
def main():
|
||||
n = 5
|
||||
lst = exercise1(n)
|
||||
print(lst)
|
||||
|
||||
exercise2(lst)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Exercise 5:
|
||||
1.)
|
||||
Write a class Student that has the following member variables:
|
||||
- Name (String)
|
||||
- Lastname (String)
|
||||
- Age (Integer)
|
||||
- Id (Integer)
|
||||
2.)
|
||||
Write a method that prints the information about the student.
|
||||
E.g. Student('Jan', 'Schaffranek', 28, 1080133228459) will print:
|
||||
'Jan Schaffranek is 28 years old and has the id 1080133228459'
|
||||
"""
|
||||
|
||||
|
||||
# Exercise 1
|
||||
class Student:
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
lastname: str,
|
||||
age: int,
|
||||
id: int, # noqa: A002
|
||||
) -> None:
|
||||
self.name = name
|
||||
self.lastname = lastname
|
||||
self.age = age
|
||||
self.id = id
|
||||
|
||||
# Exercise 2
|
||||
def print_student(self) -> None:
|
||||
print(
|
||||
f"{self.name} {self.lastname} is {self.age} years"
|
||||
f" old and has the id {self.id}"
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
oskar = Student("Oskar", "Oskarson", 29, 1080132254623)
|
||||
oskar.print_student()
|
||||
jan = Student("Jan", "Schaffranek", 28, 1080133228459)
|
||||
jan.print_student()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,13 @@
|
||||
list_a = [1, 2, 3]
|
||||
|
||||
list_a.append(4)
|
||||
|
||||
print(list_a)
|
||||
|
||||
# Tuple
|
||||
|
||||
tuple_a = (2, True, "hello", 2)
|
||||
|
||||
print(tuple_a.count(2))
|
||||
|
||||
print(tuple_a.index(2))
|
||||
@@ -0,0 +1,34 @@
|
||||
from typing import List
|
||||
|
||||
|
||||
def list_max(input_list: List) -> None:
|
||||
max_value = input_list[0]
|
||||
|
||||
for i in range(1, len(input_list)):
|
||||
if input_list[i] > max_value:
|
||||
max_value = input_list[i]
|
||||
|
||||
print(max_value)
|
||||
|
||||
|
||||
def list_min(input_list: List) -> None:
|
||||
max_value = input_list[0]
|
||||
|
||||
for i in range(1, len(input_list)):
|
||||
if input_list[i] < max_value:
|
||||
max_value = input_list[i]
|
||||
|
||||
print(max_value)
|
||||
|
||||
|
||||
def main():
|
||||
list1 = [-2, 1, 2, -10, 22, -10]
|
||||
list_max(list1)
|
||||
list_min(list1)
|
||||
list2 = [-20, 123, 112, -10, 22, -120]
|
||||
list_max(list2)
|
||||
list_min(list2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,29 @@
|
||||
list_a = [100.0, 200.0, -10.0]
|
||||
list_b = [False, False, True]
|
||||
|
||||
# index
|
||||
for idx in range(len(list_a)):
|
||||
print(idx, list_a[idx], list_b[idx])
|
||||
|
||||
|
||||
print("")
|
||||
|
||||
|
||||
# values for multiple iterables
|
||||
for val_a, val_b in zip(list_a, list_b):
|
||||
print(val_a, val_b)
|
||||
|
||||
|
||||
print("")
|
||||
|
||||
|
||||
# index and value
|
||||
for idx, val in enumerate(list_a):
|
||||
print(idx, val)
|
||||
|
||||
|
||||
print("")
|
||||
|
||||
# index and values for multiple iterables
|
||||
for idx, (val_a, val_b) in enumerate(zip(list_a, list_b)):
|
||||
print(idx, val_a, val_b)
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
my_value1 = 27
|
||||
my_value2 = "Jan"
|
||||
|
||||
|
||||
print(f"Age: {my_value1} Name: {my_value2}")
|
||||
|
||||
print("Age: ", my_value1, " Name: ", my_value2)
|
||||
|
||||
print(f"Age: {my_value1} Name: {my_value2}")
|
||||
|
||||
print(f"Age: {my_value1} Name: {my_value2}")
|
||||
@@ -0,0 +1,2 @@
|
||||
Jan Schaffranek
|
||||
Peter Peterson
|
||||
@@ -0,0 +1,3 @@
|
||||
Jan Schaffranek
|
||||
Peter Peterson
|
||||
Tom Tomerson
|
||||
Reference in New Issue
Block a user