Skip to content

Instantly share code, notes, and snippets.

@habi
Created May 18, 2025 18:34
Show Gist options
  • Save habi/1232f48ee245c8c87c4c79092c00a8c4 to your computer and use it in GitHub Desktop.
Save habi/1232f48ee245c8c87c4c79092c00a8c4 to your computer and use it in GitHub Desktop.
PLZ
# Das ist das Programm für die PLZ von Sörenberg zu
postleitzahl = 1
while True:
try:
postleitzahl = int(input("Gib eine Schweizerische Postleitzahl ein: "))
if postleitzahl < 1000 or postleitzahl >= 10000:
print("Die Zahl muss zwischen 1000 und 9999 liegen.")
continue
if str(postleitzahl)[0] == str(postleitzahl)[1] == str(postleitzahl)[2] == str(postleitzahl)[3]:
print('Du darfst keine Schnapszahl eingeben!')
continue
break
except:
print("Du musst eine Zahl eingeben")
wievielmal = 0
while postleitzahl != 6174:
wievielmal += 1
print('Im %s. Versuch startest du in %s:' % (wievielmal, postleitzahl), end='')
ZahlenSortiertGross = sorted([int(i) for i in str(postleitzahl)], reverse=True)
ZahlenSortiertKlein = sorted([int(i) for i in str(postleitzahl)])
#print(ZahlenSortiertGross)
#print(ZahlenSortiertKlein)
grossePostleitzahl = int(''.join([str(i) for i in ZahlenSortiertGross]))
kleinePostleitzahl = int(''.join([str(i) for i in ZahlenSortiertKlein]))
postleitzahl = grossePostleitzahl - kleinePostleitzahl
print(' Rechne %04s - %04s und nimm %04s für den nächsten Versuch.' % (grossePostleitzahl, kleinePostleitzahl, postleitzahl))
print('Du bist in %s Versuchen in %s (Sörenberg) angekommen' % (wievielmal, postleitzahl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment