Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # convert word to integer and vice versa
- def word_to_int(word):
- x = [ord(i) for i in word]
- print(f'letter of {word} are represented as a list of integers as below:\n{x}')
- result = 0
- for i in x:
- # keep each number in the same order
- result = result * 1000 + i
- return result
- def int_to_word(num):
- word = ''
- while num > 0:
- word = chr(num % 1000) + word
- num //= 1000
- return word
- result = word_to_int('Mohammed')
- print(result)
- result = int_to_word(result)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement