Created
March 19, 2014 01:43
-
-
Save calebreister/9633956 to your computer and use it in GitHub Desktop.
This is a simple string manipulation example in Python... the program is based loosely on the 1st assignment I did in CS162.
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
def checkVowels(inStr): | |
#Expects inStr to be 1 character long | |
vowels = ['A','a','E','e','I','i','O','o','U','u'] | |
for v in range(len(vowels)): | |
if inStr == vowels[v]: | |
return True | |
return False | |
def rmVowels(inStr): | |
out = [] | |
for i in range(len(inStr)): | |
if not (checkVowels(inStr[i])): | |
out.append(inStr[i]) | |
else: out.append('') | |
return ''.join(out)#convert list to a string, drops list formatting | |
myName = "Caleb Reister" | |
userGuess = input("Guess what my name is: ") | |
#Print guess results | |
print("You chose: ", end='') | |
if userGuess == myName: | |
print("wisely") | |
else: | |
print("poorly") | |
#remove vowels from the user's guess | |
print("You Entered:", userGuess) | |
print("Without vowels, that is:", rmVowels(userGuess)) | |
#append "the Barbarian" | |
print("In less civilized times (such as the times CS162 class has", | |
"recreated very accurately), you might be known as:", | |
userGuess, "the Barbarian") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment