LoginSignup
0
0

More than 1 year has passed since last update.

paizaラーニング問題集「大きな数値を 3 けたごとにカンマ区切りで」Python3編

Last updated at Posted at 2023-04-30

表示だけならformat文を使えば一発だけど、アルゴリズムの勉強と思って自力で組みました。
これで100点取れました。
(現在のランク:C)

実は正解提出前にお手つき1回してます(50点)。

# coding: utf-8

def add_comma(s):
  temp = list(reversed(s))
  dgt = []
  for i in range(len(temp)):
    if (i % 3 == 0) and (i != 0):
      dgt.append(",")
    dgt.append(temp[i])
  new_list = list(reversed(dgt))
  result = "".join(new_list)
  return(result)

big_num_str = input()

num_list = list(big_num_str)
new_number = add_comma(num_list)
print(new_number)
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0