some new things, mostly not working or finished
This commit is contained in:
5
functions/firstlast.py
Normal file
5
functions/firstlast.py
Normal file
@@ -0,0 +1,5 @@
|
||||
def wort_funktion(s : str) -> str:
|
||||
last = len(s)
|
||||
print(s[0] + s[(len(s)) - 1])
|
||||
|
||||
wort_funktion("das ist ein string!")
|
||||
70
functions/mark/main.py
Normal file
70
functions/mark/main.py
Normal file
@@ -0,0 +1,70 @@
|
||||
# Datei <20>ffnen
|
||||
|
||||
f = open("login.txt", "a")
|
||||
|
||||
|
||||
#Login Prozess
|
||||
|
||||
def login():
|
||||
benutzername = input("Geben sie ihre Benutzername ein:")
|
||||
passwort = input("Geben Sie Ihren Passwort ein:")
|
||||
|
||||
global Registrierung
|
||||
Registrierung = False #Sagt dem Programm ob der Nutzer in Zukunft registrieren m<>chte
|
||||
falscherPasswort = False
|
||||
try:
|
||||
# Auslesen der Datei
|
||||
with open("login.txt", "r") as f:
|
||||
accounts = f.readlines()
|
||||
|
||||
angemeldet = False
|
||||
|
||||
for account in accounts:
|
||||
name, pw = account.strip().split(",")
|
||||
if benutzername == name and passwort == pw:
|
||||
angemeldet = True
|
||||
falscherPasswort = False
|
||||
break
|
||||
elif benutzername == name and not passwort == pw:
|
||||
falscherPasswort = True
|
||||
|
||||
if angemeldet and not falscherPasswort:
|
||||
print("Anmeldung erfolgreich!")
|
||||
elif falscherPasswort:
|
||||
print("Benutzername oder Passwort falsch (pw)")
|
||||
|
||||
else:
|
||||
print("Benutzername oder Passwort falsch")
|
||||
|
||||
newaccount = input("Wollen Sie einen neuen Account erstellen?")
|
||||
if newaccount == "Ja":
|
||||
Registrierung = True
|
||||
else:
|
||||
Registrierung = False
|
||||
|
||||
|
||||
|
||||
except FileNotFoundError:
|
||||
print("Datei wurde nicht gefunden")
|
||||
|
||||
# Funktion zur Registrierung
|
||||
def signin():
|
||||
newname = input("Geben Sie ihr neuer Benutzername ein:")
|
||||
newpw = input("Geben Sie ihr neues Passwort ein:")
|
||||
with open("login.txt", "a") as f:
|
||||
f.write("\n"+newname+",")
|
||||
f.write(newpw+"\n")
|
||||
|
||||
print("Dein Account wurde erfolgreich registriert!")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
login()
|
||||
|
||||
# Aufruf der Funktion falls der Nutzer registrieren will
|
||||
if Registrierung:
|
||||
signin()
|
||||
|
||||
52
functions/passwort.py
Normal file
52
functions/passwort.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import random
|
||||
|
||||
def passwort_zahlen(laenge):
|
||||
p = ""
|
||||
for _ in range(laenge):
|
||||
zufallszahl = random.randint(0, 9)
|
||||
p = str(p) + str(zufallszahl)
|
||||
return p
|
||||
|
||||
def passwort_buchstaben(laenge):
|
||||
p = ""
|
||||
for _ in range(laenge):
|
||||
buchstabe = random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
p = str(p) + str(buchstabe)
|
||||
return p
|
||||
|
||||
def passwort_kombi(laenge):
|
||||
p = ""
|
||||
for _ in range(laenge):
|
||||
wahl = random.choice(["zahl", "buchstabe"])
|
||||
if wahl == "zahl":
|
||||
zufallszahl = random.randint(0, 9)
|
||||
p = str(p) + str(zufallszahl)
|
||||
else:
|
||||
buchstabe = random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
p = str(p) + str(buchstabe)
|
||||
return p
|
||||
|
||||
# Hauptprogramm
|
||||
def main():
|
||||
print("Passwortgenerator")
|
||||
print("1: Nur Zahlen")
|
||||
print("2: Nur Buchstaben")
|
||||
print("3: Zahlen und Buchstaben")
|
||||
|
||||
auswahl = input("Deine Wahl (1/2/3): ")
|
||||
laenge = int(input("Wie viele Zeichen soll das Passwort haben? "))
|
||||
|
||||
if auswahl == "1":
|
||||
passwort = passwort_zahlen(laenge)
|
||||
elif auswahl == "2":
|
||||
passwort = passwort_buchstaben(laenge)
|
||||
elif auswahl == "3":
|
||||
passwort = passwort_kombi(laenge)
|
||||
else:
|
||||
return
|
||||
|
||||
print("Passwort:", passwort)
|
||||
|
||||
# Programm starten
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
57
functions/sekunden.py
Normal file
57
functions/sekunden.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# -*- coding: ansi -*-
|
||||
|
||||
def timetosec(time_str):
|
||||
parts = time_str.split(':')
|
||||
parts = [int(p) for p in parts]
|
||||
|
||||
if len(parts) == 3: # HH:MM:SS
|
||||
hours, minutes, seconds = parts
|
||||
elif len(parts) == 2: # MM:SS
|
||||
hours = 0
|
||||
minutes, seconds = parts
|
||||
elif len(parts) == 1: # SS
|
||||
hours = 0
|
||||
minutes = 0
|
||||
seconds = parts[0]
|
||||
else:
|
||||
raise ValueError("Zeitformat")
|
||||
|
||||
total_seconds = hours * 3600 + minutes * 60 + seconds
|
||||
return total_seconds
|
||||
|
||||
print(timetosec("02:15:30")) # 8130
|
||||
print(timetosec("15:30")) # 930
|
||||
print(timetosec("45")) # 45
|
||||
|
||||
|
||||
def format_seconds(seconds: int) -> str:
|
||||
"""
|
||||
Meine Interpretation von dem Moodle eintrag. Der leer ist.
|
||||
Wandelt Sekunden in das n<>chst beste Format um
|
||||
:param seconds -> int
|
||||
:returns str
|
||||
"""
|
||||
if seconds < 0:
|
||||
return "falsche eingable"
|
||||
|
||||
intervals = (
|
||||
('Tag', 86400), # 60*60*24
|
||||
('Stunde', 3600), # 60*60
|
||||
('Minute', 60),
|
||||
('Sekunde', 1),
|
||||
)
|
||||
|
||||
result = []
|
||||
for name, count in intervals:
|
||||
value = seconds // count
|
||||
if value:
|
||||
seconds -= value * count
|
||||
if value == 1:
|
||||
result.append(f"{value} {name}")
|
||||
else:
|
||||
result.append(f"{value} {name}en")
|
||||
return ', '.join(result) if result else "0 Sekunden"
|
||||
|
||||
print(format_seconds(3661)) # 1std 1m 1s
|
||||
print(format_seconds(86465)) # 1t 1m 5s
|
||||
print(format_seconds(59)) # 59s
|
||||
18
functions/summe.py
Normal file
18
functions/summe.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def summe(n) -> float:
|
||||
lst = []
|
||||
for i in range(1,n):
|
||||
lst.append(i)
|
||||
formatted = " + ".join(str(x) for x in lst)
|
||||
print(f"summe = {formatted} ; sum = {total(lst)}")
|
||||
|
||||
def total(lst: list) -> float:
|
||||
total = None
|
||||
for i in lst:
|
||||
i += total
|
||||
if total:
|
||||
return total
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
summe(10)
|
||||
31
functions/umrechner.py
Normal file
31
functions/umrechner.py
Normal file
@@ -0,0 +1,31 @@
|
||||
def euroToDollar(euro_amount, kurs=1.15):
|
||||
return euro_amount * kurs
|
||||
|
||||
def dollarToEuro(dollar_amount, kurs=1.15):
|
||||
return dollar_amount / kurs
|
||||
|
||||
def main():
|
||||
print("Währungs‐Umrechner ")
|
||||
print("Aktueller Kurs: 1€ = {:.2f} USD".format(1.15))
|
||||
richtung = input("1) € auf $ \n 2) $ auf € \nIhre Wahl: ")
|
||||
if richtung == "1":
|
||||
euro_str = input("€: ")
|
||||
try:
|
||||
euro = float(euro_str.replace(",","."))
|
||||
dollar = euroToDollar(euro, kurs=1.15)
|
||||
print(f"{euro:.2f}€ entsprechen {dollar:.2f}$")
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
elif richtung == "2":
|
||||
usd_str = input("$: ")
|
||||
try:
|
||||
usd = float(usd_str.replace(",","."))
|
||||
euro = dollarToEuro(usd, kurs=1.15)
|
||||
print(f"{usd:.2f} $ entsprechen {euro:.2f}€")
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
else:
|
||||
print("wähle richtig")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user