Created
May 18, 2025 18:34
-
-
Save habi/1232f48ee245c8c87c4c79092c00a8c4 to your computer and use it in GitHub Desktop.
PLZ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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