Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array 객체
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
Archives
- Today
- In Total
A Joyful AI Research Journey🌳😊
Finding a power of 2 that starts with 65 본문
🌳Coursework Maths 2025🪄✨/Discrete Maths
Finding a power of 2 that starts with 65
yjyuwisely 2024. 1. 23. 07:00Problem)
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}')
- 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] 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'.
- 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.
- For example, if 2 ** n is 1024, str(2 ** n) is '1024', and str(2 ** n)[:2] is '10'.
- 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."
- 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
반응형
'🌳Coursework Maths 2025🪄✨ > Discrete Maths' 카테고리의 다른 글
Comments