initial commit
This commit is contained in:
18
zahlenraten/capped.py
Normal file
18
zahlenraten/capped.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import random
|
||||
|
||||
tries = 5
|
||||
num = random.randint(1,20)
|
||||
|
||||
while tries > 0:
|
||||
# debug
|
||||
# print(num)
|
||||
try:
|
||||
_ = int(input(f"{tries}: Gib eine Zahl zwischen 1 und 20 ein: "))
|
||||
except (ValueError, KeyboardInterrupt):
|
||||
pass
|
||||
|
||||
if _ == num:
|
||||
print(f"Du hast es erraten mit {tries} Versuchen")
|
||||
break
|
||||
|
||||
tries -= 1
|
||||
25
zahlenraten/main.py
Normal file
25
zahlenraten/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import random
|
||||
|
||||
# init
|
||||
tries = 1
|
||||
rand = random.randint(1,20)
|
||||
_ = int
|
||||
|
||||
while True:
|
||||
# versuche int zu bekommen, wenn string dann versuchen wirs neu!
|
||||
try:
|
||||
_ = int(input(f"{tries}: Geben Sie eine Zahl von 1 zwischen 20 ein: "))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# versuche zu vergleichen. falls irgendeine exception ist dann break!
|
||||
try:
|
||||
if _ == rand:
|
||||
print(f"Spitze mit: {tries} Versuchen. Die Zahl war {rand}")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Exception => {e}")
|
||||
break
|
||||
|
||||
# inkrementiere versuchsz<73>hler!
|
||||
tries += 1
|
||||
11
zahlenraten/passwortgenerator.py
Normal file
11
zahlenraten/passwortgenerator.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
def generate_password(length=int) -> str:
|
||||
chars = string.ascii_letters + string.digits + string.punctuation
|
||||
|
||||
password = "".join(random.choice(chars) for _ in range(length))
|
||||
return password
|
||||
|
||||
length = int(input("Gib die Laenge deines Passwortes ein: "))
|
||||
print(generate_password(length))
|
||||
Reference in New Issue
Block a user