Skip to content

Instantly share code, notes, and snippets.

@TheonlyTazz
Last active December 13, 2022 10:47
Show Gist options
  • Save TheonlyTazz/fa12b20e9ce8cec60806ec98af988d7c to your computer and use it in GitHub Desktop.
Save TheonlyTazz/fa12b20e9ce8cec60806ec98af988d7c to your computer and use it in GitHub Desktop.
RandomNumberGuesser
def Aufgaberandom(min=0, max=10):
ratezahl = random.randrange(min, max)
anzahlVersuche = 1
gefunden = False
while gefunden == False:
versuch = input('Gebe eine Nummer ein: \n')
# Kontrollier ob Zahl eingegeben ist
if versuch.isdigit() == False:
print('Bitte geben Sie nur eine Zahl ein')
# Kontrollier ob Zahl zwischen Min/Max ist
elif int(versuch) > max or int(versuch) < min:
print(f'Bitte ein Zahl zwischen {min} und {max} eingeben')
# Wenn Versuch nicht Ratezahl entspricht
elif versuch != ratezahl:
anzahlVersuche += 1
print(f'Falsch, versuchen sie es nochmal')
# Wenn Versuch den Random Nummer entspricht
elif int(versuch) == ratezahl:
print(f'Richtig. Dein Zahl war der ratezahl: {ratezahl}')
print(f'Du hast: {anzahlVersuche} Versuche gebraucht')
gefunden = True
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment