CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 10:35:41 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=78c5fe9da62d93ced64510e48ca45f21da0250f119fea5d485ab63c4366dd4eea%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22K5F8aDDGeEoyYzsN1eovYCBHbDJmTXeB%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cdb64f9e08c537-BLR
Chapter 3 (optimization) - Pastebin.com
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # Задачи на оптимизацию кода.
- # Исходная версия программы (задача -- определить индекс числа,
- # являющегося двойкой, возведенной в степень, показатель которой
- # хранится в переменной X):
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- found = False
- i = 0
- while not found and i < len(L):
- if 2 ** X == L[i]:
- found = 1
- else:
- i = i + 1
- if found:
- print("It's at index", i)
- else:
- print(X, "not found.")
- # Задачи на оптимизацию.
- # Задача №1: оптимизировать вычисление степени
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- P = 2 ** X
- i = 0
- while i < len(L):
- if P == L[i]:
- print("It's at index", i)
- break
- else:
- i = i + 1
- else:
- print(X, "not found.")
- # Задача №2: избавиться от литерала списка
- L = [2 ** i for i in range(7)]
- X = 5
- found = False
- i = 0
- while not found and i < len(L):
- if 2 ** X == L[i]:
- found = 1
- else:
- i = i + 1
- if found:
- print("It's at index", i)
- else:
- print(X, "not found.")
- # Задача №3: избавиться от флага found.
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- i = 0
- while i < len(L):
- if 2 ** X == L[i]:
- print("It's at index", i)
- break
- else:
- i = i + 1
- else:
- print(X, "not found.")
- # Задача №4: решить при помощи цикла for.
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- i = 0
- for i in L:
- if 2 ** X == i:
- print("It's at index", L.index(i))
- break
- else:
- print(X, "not found.")
- # Задача №5: решить без циклов.
- # Решение №1:
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- if (2 ** X) in L:
- print("It's at index", L.index(2 ** X))
- else:
- print(X, "not found.")
- # Решение №2
- L = [1, 2, 4, 8, 16, 32, 64]
- X = 5
- try:
- print("It's at index", L.index(2 ** X))
- except:
- print(X, "not found.")
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ Online Marketplace Exploit ✅ NEVER SEEN BE...
JavaScript | 8 sec ago | 0.24 KB
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 16 sec ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 25 sec ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 5
JavaScript | 30 sec ago | 0.24 KB
-
⭐✅ MAKE $2000 INSTANTLY ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 35 sec ago | 0.24 KB
-
⭐✅ MAKE $2500 IN 15 MIN⭐⭐⭐ 4
JavaScript | 37 sec ago | 0.24 KB
-
⭐ Free Crypto Method ✅ NEVER SEEN BEFORE ⭐⭐⭐
JavaScript | 44 sec ago | 0.24 KB
-
✅ Make $2500 in 20 minutes⭐⭐⭐ J
JavaScript | 46 sec ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand