使用类方法显示用户输入,其中奇数字母为大写字母,字母还将显示大写字母的辅音
我一直尝试到大写转换,但结果需要在辅音中显示
c = input("Enter: ")
word = list(c)
for i, x in enumerate(word):
if i % 2:
word[i] = x.upper()
print("".join(word))
for i in word:
if i.isupper():
print(i,end='')
结果看起来是谎言
输入:我是一名黑客
I A A K R(使用大写方法)
KR(仅打印辅音)
答案 0 :(得分:0)
如果您只想要辅音而不是元音,则只有一个小解决方法:
vowel_list = ['A', 'E', 'I', 'O', 'U']
for i in word:
if i.isupper():
if i not in vowel_list:
print(i,end='')
答案 1 :(得分:0)
尝试一下:
c = input("Enter: ")
word = list(c)
vowels = ['A', 'E', 'I', 'O', 'U']
upper = []
consonants = []
for i in range(0, len(word), 2):
if word[i].isalpha():
upper.append(word[i].upper())
if word[i].upper() not in vowels:
consonants.append(word[i].upper())
print(' '.join(upper))
print(' '.join(consonants))
答案 2 :(得分:0)
这是您想要的吗?
user_input = "Some sample input to check"
word_list = user_input.split(" ")
vowels = ['a', 'e', 'i', 'o', 'u']
for position, word in enumerate(word_list):
if position % 2 == 0:
word = word.upper()
print("Word ",word)
for letter in word:
if letter.lower() not in vowels:
print("Upper Case Consonant ",letter.upper())
Word SOME
Upper Case Consonant S
Upper Case Consonant M
Word INPUT
Upper Case Consonant N
Upper Case Consonant P
Upper Case Consonant T
Word CHECK
Upper Case Consonant C
Upper Case Consonant H
Upper Case Consonant C
Upper Case Consonant K