Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
210-CT/Week 3.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
190 lines (113 sloc)
3.58 KB
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 RemoveVowels(string): | |
""" enter a string in lower case and this function will remove the vowels""" | |
if 'a' in string: | |
newString = string.replace('a','') #removes the vowel from the string | |
return(RemoveVowels(newString)) #calls function again until the sting has no more vowels | |
elif 'e' in string: | |
newString = string.replace('e','') | |
return(RemoveVowels(newString)) | |
elif 'i' in string: | |
newString = string.replace('i','') | |
return(RemoveVowels(newString)) | |
elif 'o' in string: | |
newString = string.replace('o','') | |
return(RemoveVowels(newString)) | |
elif 'u'in string: | |
newString = string.replace('u','') | |
return(RemoveVowels(newString)) | |
else: | |
return('Your word without vowels >> ' + str(string)) | |
print(RemoveVowels('beautiful')) | |
#Week 3 task 1 | |
def ReverseAString(sentence): | |
listOfWords = sentence.split(" ") #splitting sentence at spaces | |
n = len(listOfWords) - 1 #index of last element in list | |
reversedList = [] | |
for i in range(len(listOfWords)): | |
#appending the words in the sentence in reverse order | |
word = listOfWords[n] | |
reversedList.append(word) | |
n = n - 1 | |
return(" ".join(reversedList)) | |
print(ReverseAString("This Is Awesome")) | |
#BigO O(n) | |
def PrimeNumber(n,x): | |
"""n is the number you want to test and x = n-1""" | |
if n <= 1: | |
return("Your Number isn't Prime") | |
elif n = 2: | |
return("Your number is Prime") | |
elif x = 1: | |
return("Your number is Prime") | |
elif n%x = 0: | |
return("Your Number isn't Prime") | |
elif n%x != 0: | |
return(PrimeNumber(n,x-1)) | |
print(PrimeNumber(17,16)) | |
print(PrimeNumber(4,3)) | |
print(PrimeNumber(1,0)) | |
#Week 3 Task 1 Pseudocode | |
#reversiving a string function | |
ReverseAString(sentence): | |
listOfWords <- split sentence at spaces | |
n <- length(listOfWords) - 1 | |
reversedList <- [] | |
FOR i <- 0 to length[listOfWords] | |
word <- listOfWords[n] | |
reversedList.append(word) | |
n <- n - 1 | |
RETURN(reversedList) | |
Big O notation for this function O(n) | |
#week 3 task 2 | |
Checking if a number is prime | |
PrimeNumber(n,x): | |
IF n <= 1: | |
return("Your Number isn't Prime") | |
ELSE IF n = 2: | |
return("Your number is Prime") | |
ELSE IF x = 1: | |
return("Your number is Prime") | |
ELSE IF n%x = 0: | |
return("Your Number isn't Prime") | |
ELSE IF n%x != 0: | |
return(PrimeNumber(n,x-1)) | |
#week 3 task 3 | |
Removing vowels function | |
RemoveVowels(string) | |
IF a in string | |
newString <- replace 'a' in string with '' | |
RETURN(RemoveVowels(newString)) | |
ELSE IF e in string | |
newString <- replace 'e' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELSE IF i in string | |
newString <- replace 'i' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELSE IF o in string | |
newString <- replace 'o' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELSE IF u in string | |
newString <- replace 'u' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELSE | |
RETURN(string) | |
#week 3 task 3 Pseudocode | |
#Removing vowels function | |
RemoveVowels(string) | |
IF a in string | |
newString <- replace 'a' in string with '' | |
RETURN(RemoveVowels(newString)) | |
ELIF e in string | |
newString <- replace 'e' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELIF i in string | |
newString <- replace 'i' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELIF o in string | |
newString <- replace 'o' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELIF u in string | |
newString <- replace 'u' in string with '' | |
RETURN(RemoveVowels(newString) | |
ELSE | |
RETURN(string) |