初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題625
def first_vowel_index(s):
for i, c in enumerate(s):
if c.lower() in ‘aeiou’:
return i
return -1
# 呼び出し例
s = “Python”
print(first_vowel_index(s)) # 出力: 1
問題626
def remove_vowels(s):
return ”.join(c for c in s if c.lower() not in ‘aeiou’)
# 呼び出し例
s = “Python”
print(remove_vowels(s)) # 出力: “Pythn”
問題627
def range_list(lst):
return max(lst) – min(lst)
# 呼び出し例
lst = [1,5,3]
print(range_list(lst)) # 出力: 4



コメント