-
Notifications
You must be signed in to change notification settings - Fork 0
/
painutilities.py
executable file
·45 lines (35 loc) · 1.18 KB
/
painutilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Import
import os
from time import sleep
# Funktion zum clearen
def clearscreen():
# Linux ähnliche Systeme
if os.name == 'posix':
os.environ['TERM'] = 'xterm-color'
os.system('clear')
# Windows
elif os.name == 'nt':
os.system('cls')
# Funktion mit Enter und clearen
def nextstep():
input('Drücke "Enter" zum Fortfahren!\n')
clearscreen()
# Funktion um falsche Eingaben abzufangen
def benutzer_zahl_eingabe(eingabe_int_liste, frage_txt = "?: ", fehleingabe_txt = "Nochmal, bitte"):
if len(eingabe_int_liste) < 2:
raise ValueError("Parameter eingabe_int_liste muss mindestens zwei Elemente enthalten")
eingabe_gueltig = False
rueckgabe = 0
while not eingabe_gueltig:
eingabe = input(frage_txt)
for i in eingabe_int_liste:
try:
rueckgabe = int(eingabe)
if i == rueckgabe:
eingabe_gueltig = True
break
except:
eingabe_gueltig = False
if not eingabe_gueltig:
print(fehleingabe_txt)
return rueckgabe