初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題628
def is_palindrome(s):
s = s.lower()
return s == s[::-1]
# 呼び出し例
s = “Level”
print(is_palindrome(s)) # 出力: True
問題629
def first_negative(lst):
for num in lst:
if num < 0:
return num
return None
#<は半角記号に変換
# 呼び出し例
lst = [1, -2, 3]
print(first_negative(lst)) # 出力: -2
問題630
def count_words(s):
return len(s.split())
# 呼び出し例
s = “Python is fun”
print(count_words(s)) # 出力: 3



コメント