Notice
Recent Posts
Recent Comments
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
In Total
관리 메뉴

A Joyful AI Research Journey🌳😊

Finding a power of 2 that starts with 65 본문

🌳Coursework Insights🪄✨/Discrete Maths

Finding a power of 2 that starts with 65

yjyuwisely 2024. 1. 23. 07:00

Problem)

Does there exist a power of 2 that starts with 65?

Solution)

for n in range (100):
if int(str(2 ** n) [:2]) == 65:
print(f'2**{n}={2**n}')
  1. In the statement for n in range(100):, the colon : is used to indicate the start of the block of code that will be executed in each iteration of the for loop. It is a fundamental part of Python's syntax for defining loops, conditionals, and other control structures.
  2. [:2] then takes the first two characters from this string. The slice starts at the beginning (index 0) and goes up to, but does not include, index 2. So, in the example of '1024', the slice [:2] would yield '10'.
  3. str(2 ** n)[:2]: Slices the string to get the first two characters. The slice [:2] starts from the beginning of the string (index 0) and goes up to, but does not include, index 2.
    1. For example, if 2 ** n is 1024, str(2 ** n) is '1024', and str(2 ** n)[:2] is '10'.
  4. In the statement print(f'2**{n}={2**n}'), the f before the opening quote marks the string as an f-string, which stands for "formatted string literal."
    1. f-string notation: The f character at the beginning of the string indicates that it is an f-string. This allows for embedded Python expressions within the string.
2**16=65536

 

728x90
반응형
Comments