furas

Python - pseudo "Morse'a Code" - (Stackoverflow)

May 7th, 2020 (edited)
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. u = '1000111001'
  2. u = '11011'
  3.  
  4. result = ""
  5.  
  6. while u:
  7.     if u.startswith("000"):
  8.         result += '333'
  9.         u = u[3:]
  10.     elif u.startswith("00"):
  11.         result += '22'
  12.         u = u[2:]
  13.     elif u.startswith("0"):
  14.         result += '1'
  15.         u = u[1:]
  16.     elif u.startswith("11"):
  17.         result += '-'
  18.         u = u[2:]
  19.     elif u.startswith("1"):
  20.         result += '.'
  21.         u = u[1:]
  22.  
  23. print(result)
Add Comment
Please, Sign In to add comment