Created
March 9, 2015 00:28
-
-
Save lindsaymarkward/b5dae3aa1003707de7df to your computer and use it in GitHub Desktop.
Check if a string contains all letters of the alphabet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Lindsay Ward, 09/03/2015 | |
Quick program to check if a string contains all letters of the alphabet | |
""" | |
__author__ = 'sci-lmw1' | |
test1 = "Playing jazz vibe chords quickly excites my wife." | |
test2 = "The quick brown fox jumped over the lazy dog." | |
letterCounts = [0] * 26 | |
# print(ord('a')) | |
words = test1.lower() | |
for letter in words: | |
if 'a' <= letter <= 'z': | |
# print(letter, ord(letter)) | |
letterCounts[ord(letter) - 97] += 1 | |
# print(letter) | |
# print(letterCounts) | |
char = 'a' | |
allLetters = True | |
for count in letterCounts: | |
print(char, count, end='\t') | |
char = chr(ord(char) + 1) | |
if count == 0: | |
allLetters = False | |
print() | |
if allLetters: | |
print("String contains all letters! :)") | |
else: | |
print("String does not contain all letters :(") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment