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

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.

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

telegram from cn


Telegram Semolina Code (Python / TypeScript)
FROM USA