我对这个练习有一个问题:
# Loop through the letters of the variable 'summer_word' from above
# Concatenate the consonants from 'summer_word' and answer with the new word.
summer_word = "music"提示:创建一个包含辅音的字符串,并检查每个字母是否在其中。
现在我怎么循环单词中的字母,但我想不出如何去掉辅音。
发布于 2022-09-09 14:07:20
尝试这段代码,可能会对您的情况有所帮助:
summer_word = "music"
consonants = "b, c, d, f, g, j, k, l, m, n, p, q, s, t, v, x, z , h, r, w, y"
new_word = " "
for letter in summer_word:
if letter in consonants:
new_word += letter
print(new_word)发布于 2022-09-09 13:58:09
让我们把它拆开。您应该:
consonants = 'qwrt...'summer_word变量consonants字符串中。
for letter in summer_word:
# do stuff...中。
if letter in consonants:
# ...这应该足以让你开始:)快乐的学习
https://stackoverflow.com/questions/73662702
复制相似问题