Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: num_key_alpha_freq_cipher.py
- """
- This script takes user input, counts the occurrences of each letter in the alphabet, and generates a numerical key representing the frequency of each letter.
- The script then displays the user input, the alphabet, and the corresponding numerical key that can be used in other scripting easily.
- Example Output:
- Enter your string: hello world!
- User Input: hello world!
- abcdefghijklmnopqrstuvwxyz
- Numerical Key: 00011001000300200100001000
- """
- # Global Variable Alphabet
- alphabet = 'abcdefghijklmnopqrstuvwxyz'
- def count_letters(input_string):
- letter_count = {char: 0 for char in alphabet}
- for char in input_string:
- if char.isalpha():
- letter_count[char.lower()] += 1
- count_string = ''.join(str(letter_count[char]) for char in alphabet)
- return count_string
- # Get User Input
- user_input = input("Enter your string: ")
- num_key = count_letters(user_input)
- print('\nUser Input: ', user_input, '\n')
- print('\t\t' + alphabet)
- print('Numerical Key: ', num_key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement