Python 我只想打印用户输入的辅音
显示用户输入,其中奇数字母为大写字母,字母还将使用class方法显示大写辅音 我一直尝试到大写转换,但结果需要以辅音显示Python 我只想打印用户输入的辅音,python,python-3.x,Python,Python 3.x,显示用户输入,其中奇数字母为大写字母,字母还将使用class方法显示大写辅音 我一直尝试到大写转换,但结果需要以辅音显示 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='') 结果似
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 K R(使用大写方法)
KR(仅打印辅音)
如果您只想要辅音而不是元音,那么有一个小小的修正:
vowel_list = ['A', 'E', 'I', 'O', 'U']
for i in word:
if i.isupper():
if i not in vowel_list:
print(i,end='')
试试这个:
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))
这是你想要的吗
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
枚举
在其计数中包含空格。是否需要?最后一步中只包含字母如果要使用类方法,则应定义类。其中许多不是元音。英语的元音是['a','e','i','o','u']
,其中'y'
有时根据上下文包括在内。对不起,我的错:'D'