Python 入門指南 V2.00 - 單元 15 範例及練習程式碼



encrypt02.py


# 定義 Encrypt 類別 
class Encrypt:
   def __init__(self):
      self.setcode()

   def setcode(self):
      # 取得 a 、 b 值
      a = 3
      b = 5
      
      # 利用公式建立密碼表
      self.code = ""
      c = "a"
      i = 0
      while i < 26:
         x = c
         y = ord(x) * a + b
         m = y % 26
         self.code += chr(m + 97)
         c = chr(ord(c) + 1)
         i += 1

   def getcode(self):
      return self.code

   # 編碼的方法
   def toEncode(self, str):
      pass

   # 解碼的方法 
   def toDecode(self, str):
      pass

# 測試部分
if __name__ == '__main__':
   e = Encrypt()
   print()
   print(e.getcode())
   print()
 
# 檔名: encrypt02.py 
# 作者: Kaiching Chang 
# 時間: July, 2014

exercise1501.py


answer = 1234

if __name__ == "__main__":
   guess = int(input(": "))
   if guess == answer:
      print("Right!!")
   else:
      print("Wrong!!")
 
# 檔名: exercise1501.py 
# 作者: Kaiching Chang 
# 時間: July, 2014

exercise1502.py


answer = "1234"

if __name__ == "__main__":
   guess = input(": ")
   if guess == answer:
      print("Right!!")
   else:
      print("Wrong!!")
 
# 檔名: exercise1502.py 
# 作者: Kaiching Chang 
# 時間: July, 2014

the end

沒有留言: