Telegram Group & Telegram Channel
Просто мозг не привык разбивать задачи на мелкие части и придумывать каждый шаг
Вот для вас всех алгоритм как решать задачи с циклом на примере задачи с равнобедренным треугольником.

1) забейте на цикл и забудьте, что он существует. Решите задачу с помощью принтов:
print(“ *”)
print(“ ***”)
print(“*****”)
Результат:
*
***
*
2) анализируем закономерности в print.
Пробелы: сначала 2, потом 1, потом 0 (на каждом шаге -1)
Звёздочки: сначала 1, потом 3, потом 5 (на каждом шаге + 2)
3) делаем принты одинаковые (с помощью переменной)
spaces = 2
stars = 1
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
Получаем 3 строчки которые повторяются 3 раза
4) пытаемся понять как это связать с данными, которые ввёл пользователь (в нашем случае высота = h = 3)
spaces в примере изначально была = 2
Это по сути h - 1
stars в любом случае вначале всегда должна равняться 1 (так как это вершина)
5) сколько итераций должен сделать цикл? Столько же сколько и высота:
i = 0
while i < h:

i += 1
6) добавим в цикл наш код:
i = 0
while i < h:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
i += 1
7) добавим переменные, которые зависят от пользователя:
h = int(input())
spaces = h - 1
start = 1
i = 0
while i < h:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
i += 1
8) уже всё работает - пытаемся оптимизировать: можно убрать переменную i и использовать как счётчик переменную spaces (но в условии нужно будет писать spaces >= 0 так как цикл должен закончиться, когда закончатся пробелы)
Получаем неплохой код:
h = int(input())
spaces = h - 1
stars = 1
while spaces >= 0:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2

SemolinaCode | Chat | YouTube | Arbuzers | HowToCode | Prop



tg-me.com/semolina_code_python/11
Create:
Last Update:

Просто мозг не привык разбивать задачи на мелкие части и придумывать каждый шаг
Вот для вас всех алгоритм как решать задачи с циклом на примере задачи с равнобедренным треугольником.

1) забейте на цикл и забудьте, что он существует. Решите задачу с помощью принтов:
print(“ *”)
print(“ ***”)
print(“*****”)
Результат:
*
***
*
2) анализируем закономерности в print.
Пробелы: сначала 2, потом 1, потом 0 (на каждом шаге -1)
Звёздочки: сначала 1, потом 3, потом 5 (на каждом шаге + 2)
3) делаем принты одинаковые (с помощью переменной)
spaces = 2
stars = 1
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
Получаем 3 строчки которые повторяются 3 раза
4) пытаемся понять как это связать с данными, которые ввёл пользователь (в нашем случае высота = h = 3)
spaces в примере изначально была = 2
Это по сути h - 1
stars в любом случае вначале всегда должна равняться 1 (так как это вершина)
5) сколько итераций должен сделать цикл? Столько же сколько и высота:
i = 0
while i < h:

i += 1
6) добавим в цикл наш код:
i = 0
while i < h:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
i += 1
7) добавим переменные, которые зависят от пользователя:
h = int(input())
spaces = h - 1
start = 1
i = 0
while i < h:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2
i += 1
8) уже всё работает - пытаемся оптимизировать: можно убрать переменную i и использовать как счётчик переменную spaces (но в условии нужно будет писать spaces >= 0 так как цикл должен закончиться, когда закончатся пробелы)
Получаем неплохой код:
h = int(input())
spaces = h - 1
stars = 1
while spaces >= 0:
print(“ ” * spaces + stars * “*”)
spaces -= 1
stars += 2

SemolinaCode | Chat | YouTube | Arbuzers | HowToCode | Prop

BY Semolina Code (Python / TypeScript)




Share with your friend now:
tg-me.com/semolina_code_python/11

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

To pay the bills, Mr. Durov is issuing investors $1 billion to $1.5 billion of company debt, with the promise of discounted equity if the company eventually goes public, the people briefed on the plans said. He has also announced plans to start selling ads in public Telegram channels as soon as later this year, as well as offering other premium services for businesses and users.

telegram from it


Telegram Semolina Code (Python / TypeScript)
FROM USA