回答編集履歴
1
f-strings を利用する例を追記
answer
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
Pythonの場合、[bin()](https://docs.python.org/3.13/library/functions.html#bin) と [int.bit_length()](https://docs.python.org/3.13/library/stdtypes.html#int.bit_length) が用意されていますので、それらを利用すると以下の様に書くことができます。
|
1
|
+
Pythonの場合、[bin()](https://docs.python.org/3.13/library/functions.html#bin) と [int.bit_length()](https://docs.python.org/3.13/library/stdtypes.html#int.bit_length) が用意されていますので、それらを利用すると以下の様に書くことができます。
|
2
2
|
```python
|
3
3
|
N = int(input())
|
4
4
|
count = 10
|
5
5
|
bin_str = '0'*(count - N.bit_length()) + bin(N)[2:]
|
6
6
|
print(bin_str)
|
7
7
|
```
|
8
|
+
もしくは f-strings を利用します。参考にしてみてください。
|
9
|
+
```python
|
10
|
+
N = int(input())
|
11
|
+
print(f'{N:010b}')
|
12
|
+
```
|