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 Does Bitcoin Work?

Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”

The messaging service and social-media platform owes creditors roughly $700 million by the end of April, according to people briefed on the company’s plans and loan documents viewed by The Wall Street Journal. At the same time, Telegram Group Inc. must cover rising equipment and bandwidth expenses because of its rapid growth, despite going years without attempting to generate revenue.

telegram from id


Telegram Semolina Code (Python / TypeScript)
FROM USA