initial commit
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user