Last active
August 3, 2020 13:58
-
-
Save kotoripiyopiyo/64598757885cae50537d870d424198d1 to your computer and use it in GitHub Desktop.
round関数の謎を追った。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ダメな例 | |
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("処理を終了します") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#良い例 | |
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