Compare commits
3
Commits
e505364b47
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b011c1d0ca | ||
|
|
546ff352b4 | ||
|
|
b28590a630 |
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,125 @@
|
||||
import math
|
||||
import random
|
||||
|
||||
|
||||
def primfactors(n, divisor=2):
|
||||
if n == 1:
|
||||
return []
|
||||
|
||||
if not n % divisor:
|
||||
return [divisor] + primfactors(n // divisor, divisor)
|
||||
|
||||
return primfactors(n, divisor + 1)
|
||||
|
||||
|
||||
def harmon(n, val=0):
|
||||
if not n:
|
||||
return 0
|
||||
|
||||
val += harmon(n - 1, 1 / n)
|
||||
return val
|
||||
|
||||
|
||||
def usum(n, res=1):
|
||||
if not n:
|
||||
return 0
|
||||
|
||||
res += usum(n - 1, res + 2)
|
||||
return res
|
||||
|
||||
|
||||
def a4(x):
|
||||
return (lambda x: 7 * x)(x)
|
||||
|
||||
|
||||
def b4(x):
|
||||
return (lambda x: math.pow(x, 3 / 5))(x)
|
||||
|
||||
|
||||
def reverse(a: list):
|
||||
if len(a) == 1:
|
||||
return a
|
||||
|
||||
# Reverse first and last
|
||||
a[0], a[-1] = a[-1], a[0]
|
||||
|
||||
# return [a[0], reverse(a[1:-2]), a[-1]]
|
||||
return [a[0]] + reverse(a[1:-1]) + [a[-1]]
|
||||
|
||||
|
||||
class Ticket:
|
||||
event = ""
|
||||
price_class = 0
|
||||
|
||||
def __init__(self, price, num, is_valid) -> None:
|
||||
self.price = price
|
||||
self.num = num
|
||||
self.is_valid = is_valid
|
||||
|
||||
def __str__(self):
|
||||
return f"Price: {self.price}; \n Number: {self.num} \nValid: {self.is_valid}"
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"Price: {self.price}; \n Number: {self.num} \nValid: {self.is_valid}"
|
||||
|
||||
def convert(self, course):
|
||||
new_price = self.price * course
|
||||
print(f"Price with course: {course} is {new_price}")
|
||||
return new_price
|
||||
|
||||
def get_is_valid(self):
|
||||
return self.is_valid
|
||||
|
||||
|
||||
def fill_tickets():
|
||||
return [
|
||||
Ticket(i * 10, num=random.random() * i, is_valid=True if i % 3 else False)
|
||||
for i in range(12)
|
||||
]
|
||||
|
||||
|
||||
def writeTicketFile(ticket_list: list):
|
||||
with open("ticket_list.txt", "+w") as f:
|
||||
f.writelines(
|
||||
[f"Ticket {i}: {t.__str__()} \n\n" for t, i in enumerate(ticket_list)]
|
||||
)
|
||||
|
||||
|
||||
class TicketA(Ticket):
|
||||
price_class = "A"
|
||||
|
||||
def write_to_file(self):
|
||||
with open(f"{self.price_class}.txt", "a") as file:
|
||||
file.write(self.__str__() + "\n")
|
||||
|
||||
|
||||
class TicketB(Ticket):
|
||||
price_class = "B"
|
||||
|
||||
def write_to_file(self):
|
||||
with open(f"{self.price_class}.txt", "a") as file:
|
||||
file.write(self.__str__() + "\n")
|
||||
|
||||
|
||||
class TicketC(Ticket):
|
||||
price_class = "C"
|
||||
|
||||
def write_to_file(self):
|
||||
with open(f"{self.price_class}.txt", "a") as file:
|
||||
file.write(self.__str__() + "\n")
|
||||
|
||||
|
||||
class TicketD(Ticket):
|
||||
price_class = "D"
|
||||
|
||||
def write_to_file(self):
|
||||
with open(f"{self.price_class}.txt", "a") as file:
|
||||
file.write(self.__str__() + "\n")
|
||||
|
||||
|
||||
def main():
|
||||
writeTicketFile(fill_tickets())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,10 @@
|
||||
## 2.2 Endrekursion
|
||||
|
||||
|
||||
Keine endrekursion ->
|
||||
|
||||
1 + 2 + 3 + 4 + 5 + 6 + sum(...)
|
||||
|
||||
Endrekursion ->
|
||||
|
||||
sum (sum(sum(sum(sum(5)))))
|
||||
@@ -0,0 +1,25 @@
|
||||
## Dekorator
|
||||
Eine Funktion mit einer anderen Funktion als Parameter
|
||||
|
||||
```python
|
||||
@DekoratorFunktion
|
||||
def funktionXY(p1, p2):
|
||||
pass
|
||||
```
|
||||
|
||||
Args und Quarks
|
||||
|
||||
|
||||
## Endrekursion
|
||||
|
||||
Der Rekursionsterm hat nur einen Funktionsaufruf. Arithmetik wird innerhalb der Argumente gemacht.
|
||||
|
||||
```python
|
||||
|
||||
# Bad example
|
||||
return func(a, b) + 1
|
||||
|
||||
# Correct example
|
||||
return func(a + 1, b)
|
||||
```
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
22.05.25 Projekt Präsentation
|
||||
|
||||
30.06.25 Projekt Abgabe
|
||||
|
||||
|
||||
|
||||
## Projekt
|
||||
|
||||
Forschungsfrage: Basically "Kann man Problem XY lösen durch Ansatz Z?"
|
||||
Reference in new issue
Block a user