初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題589
def reverse_string(s):
return s[::-1]
# 呼び出し例
s = “Python”
print(reverse_string(s)) # 出力: “nohtyP”
問題590
def split_words(s):
return s.split()
# 呼び出し例
s = “Hello world”
print(split_words(s)) # 出力: [‘Hello’, ‘world’]
問題591
def count_words(s):
return len(s.split())
# 呼び出し例
s = “Python is fun”
print(count_words(s)) # 出力: 3



コメント