Advertisement
yiwen_akeni

program to check if imei number valid or not

Oct 6th, 2022
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | Source Code | 0 0
  1. # program to check if imei number valid or not - open source totaly free
  2. from PyQt6.QtWidgets import QApplication, QMainWindow, QLabel, QLineEdit, QVBoxLayout, QWidget
  3.  
  4. import sys
  5.  
  6.  
  7. class MainWindow(QMainWindow):
  8.     def __init__(self):
  9.         super().__init__()
  10.  
  11.         self.setWindowTitle("My App")
  12.  
  13.         self.label = QLabel()
  14.  
  15.         self.input = QLineEdit()
  16.        
  17.         self.input.textChanged.connect(self.func)
  18.  
  19.         layout = QVBoxLayout()
  20.         layout.addWidget(self.input)
  21.         layout.addWidget(self.label)
  22.  
  23.         container = QWidget()
  24.         container.setLayout(layout)
  25.  
  26.         # Set the central widget of the Window.
  27.         self.setCentralWidget(container)
  28.  
  29.  
  30. # Driver code
  31.     def func(self, n):
  32.         def sumDig( n ):
  33.            a = 0
  34.            while n > 0:
  35.                 a = a + n % 10
  36.                 n = int(n / 10)
  37.  
  38.            return a
  39.  
  40. # Returns True if n is valid EMEI
  41.         def isValidEMEI(n):
  42.  
  43. # Converting the number into
  44.     # String for finding length
  45.            s = str(n)
  46.            l = len(s)
  47.  
  48.     # If leng+th is not 15 then IMEI is Invalid
  49.            if l != 15:
  50.                 return False
  51.  
  52.            d = 0
  53.            sum = 0
  54.            for i in range(15, 0, -1):
  55.                    d = (int)(int(n) % 10)
  56.                    if i % 2 == 0:
  57.  
  58.             # Doubling every alternate digit
  59.                         d = 2 * d
  60.  
  61.         # Finding sum of the digits
  62.                    sum = sum + sumDig(d)
  63.                    n = int(n) / 10
  64.            return (sum % 10 == 0)
  65.  
  66.         if isValidEMEI(n):
  67.            self.label.setText("\nValid IMEI Code\n")
  68.        
  69.         else:
  70.            self.label.setText("WRONG or Invalid IMEI")
  71.  
  72.            
  73.  
  74. app = QApplication(sys.argv)
  75.  
  76. window = MainWindow()
  77. window.show()
  78.  
  79. app.exec()
Tags: python pyqt6 imei
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement