0
대문자 문자열의 두 번째 절반에 모든 모음을 만들려고합니다. 이것은 내가 지금까지 한 일이며, 내가 원하는 결과를 얻지 못하는 것입니다.문자열의 뒷부분에있는 모든 모음을 어떻게 대문자로 만들 수 있습니까?
#Ask user for word
word = str(input("Please enter a word: "))
#Count word length
wordLen = len(word)
#Count half of word length
halfWordLen = int (wordLen/2)
#Obtain 1st and 2nd half of the word
firstHalf = word[:halfWordLen]
secondHalf = word[halfWordLen:]
#Determine vowels
vowels = set(['a','e','i','o','u'])
#Iterate through 2nd half to find vowel.
#Then, uppercase the vowels, and display new word.
for char in secondHalf:
if char in vowels:
newWord = firstHalf + secondHalf.replace(char,(char.upper()))
print ("The new word is: ",newWord)
결과 :
Please enter a word: abrasion
The new word is: abrasIon
The new word is: abrasiOn
해야하는데 :
Please enter a word: abrasion
The new word is: abrasIOn