Skip to content

Instantly share code, notes, and snippets.

@kotoripiyopiyo
Last active August 3, 2020 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotoripiyopiyo/64598757885cae50537d870d424198d1 to your computer and use it in GitHub Desktop.
Save kotoripiyopiyo/64598757885cae50537d870d424198d1 to your computer and use it in GitHub Desktop.
round関数の謎を追った。
#ダメな例
h = 0
i = str(0)
j = 11
while j != 10:
number = float(str(10.5) + (i * h) + str(1))
rounding = round(number)
print(str(number) + ' is ' + str(rounding))
h += 1
j = rounding
print("処理を終了します")
#良い例
h = 0
i = str(0)
j = 11
while j != 10:
number_str = str(10.5) + (i * h) + str(1)
number = float(number_str)
rounding = round(number)
print(number_str + ' is ' + str(rounding))
h += 1
j = rounding
print("処理を終了します")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment