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: |

What Is Bitcoin?

Bitcoin is a decentralized digital currency that you can buy, sell and exchange directly, without an intermediary like a bank. Bitcoin’s creator, Satoshi Nakamoto, originally described the need for “an electronic payment system based on cryptographic proof instead of trust.” Each and every Bitcoin transaction that’s ever been made exists on a public ledger accessible to everyone, making transactions hard to reverse and difficult to fake. That’s by design: Core to their decentralized nature, Bitcoins aren’t backed by the government or any issuing institution, and there’s nothing to guarantee their value besides the proof baked in the heart of the system. “The reason why it’s worth money is simply because we, as people, decided it has value—same as gold,” says Anton Mozgovoy, co-founder & CEO of digital financial service company Holyheld.

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

telegram from vn


Telegram Semolina Code (Python / TypeScript)
FROM USA