Advertisement
Florian-Binder

Warencode Python

Oct 17th, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*-coding: utf-8 -*-
  3.  
  4. import sys, os
  5.  
  6. Fehlercode = ["kein Fehler", " String enthält nicht ausschließlich Ziffern", "Nettogewicht ist größer als Bruttogewicht"]
  7. code = "000024740002506831001250"
  8.  
  9.  
  10.  
  11. def destroy():
  12.     sys.exit()
  13.  
  14.  
  15. if __name__ == '__main__':
  16.     try:
  17.         #code = input() #eingabe eines 24 stelligen Codes
  18.  
  19.         anz = 0
  20.         zehner = 1
  21.         netto = 0
  22.         brutto = 0
  23.        
  24.         while anz < 23: #Überprüfen auf Buchstaben
  25.             if not (code[anz] >= '0' and code [anz] <= '9'):
  26.                 print (Fehlercode[1])
  27.                 destroy()
  28.             anz += 1  
  29.        
  30.         anz = 13
  31.         while anz > 8: #Netto gewicht
  32.             netto += int(code[anz]) * zehner
  33.             anz -= 1
  34.             zehner *= 10
  35.  
  36.         anz = 23
  37.         zehner = 1
  38.         while anz > 18: #Brutto gewicht
  39.             brutto += int(code[anz]) * zehner
  40.             anz -= 1
  41.             zehner *= 10
  42.          
  43.         if netto > brutto:
  44.             print (Fehlercode[2])
  45.         else:
  46.             print (Fehlercode[0])
  47.  
  48.     except KeyboardInterrupt:  # wenn 'CTRL-C' gedrückt, dann Ende
  49.         destroy()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement