Compare commits
6 Commits
a97cdecca5
...
a9726cf034
Author | SHA1 | Date | |
---|---|---|---|
a9726cf034 | |||
14ef6f4e14 | |||
7a85c279c2 | |||
1173214090 | |||
59978523a4 | |||
d1f553057a |
@ -25,6 +25,11 @@ __\n__ - перенос фразы на след. строку
|
||||
__\t__ - заменяет пробел в строке
|
||||
|
||||
__""" _ """__ - игнорируют любые символы внутри
|
||||
- из списка подряд цифры через пробел
|
||||
```python
|
||||
L = [1, 2, 3, 4, 5]
|
||||
print(*L)
|
||||
```
|
||||
|
||||
|
||||
## Строки в Python
|
||||
|
@ -1,6 +1,11 @@
|
||||
## Lists []
|
||||
- Пример листа `list = [1, 'num', 3.33]` *Можно создавать эл-ты разных ТД*
|
||||
- Длину можно узнать `len()` (выдаст именно ко-во эл-во, не индексы)
|
||||
- из списка подряд цифры через пробел
|
||||
```python
|
||||
L = [1, 2, 3, 4, 5]
|
||||
print(*L)
|
||||
```
|
||||
- Выбрать по индексу `list[index]` -> выдаст эл-т
|
||||
- Вырезать по индексу `list[:2]` -> выдаст все выбранные
|
||||
- __МОЖНО__ менять эл-ты в списке `list[index]='hi'`
|
||||
@ -44,4 +49,38 @@ for num in list:
|
||||
print (sum) -> 10
|
||||
```
|
||||
|
||||
## Nested Loops - вложенные циклы
|
||||
## Nested Loops - вложенные циклы
|
||||
- треугольник из смайликов `\U0001f600`
|
||||
```python
|
||||
for num in range(10):
|
||||
count=0
|
||||
emoticons = ''
|
||||
while count <=num:
|
||||
emoticons+='\U0001f600'
|
||||
count+=1
|
||||
print (emoticons) -> 😀
|
||||
😀😀
|
||||
😀😀😀
|
||||
😀😀😀😀
|
||||
😀😀😀😀😀
|
||||
😀😀😀😀😀😀
|
||||
😀😀😀😀😀😀😀
|
||||
😀😀😀😀😀😀😀😀
|
||||
😀😀😀😀😀😀😀😀😀
|
||||
😀😀😀😀😀😀😀😀😀😀
|
||||
```
|
||||
- то же, но без `while`
|
||||
```python
|
||||
for num in range(10):
|
||||
emoticons = ''
|
||||
for count in range(num+1):
|
||||
emoticons+='\U0001f600'
|
||||
print(emoticons)
|
||||
```
|
||||
#### Мультприкация строк
|
||||
```python
|
||||
for num in range(1,11): # не с -, т.к. 0 = 0, пропуск -> 1) 1*1= 1 \ 2) 1*2= 2 \ 3) 1*3= 3
|
||||
print('\U0001f600'*num) # при умножении строки на число мы получаем строку несколько раз, а for сделал это range (1,11)(т.е. 10) раз
|
||||
```
|
||||
|
||||
HUYodjsyvd888399472749 -tvoistaj
|
@ -30,6 +30,7 @@ Among them there are:
|
||||
- [Sapper game](stepik/stepik_tasks/sapper.py)
|
||||
- [sum_num_from_last](stepik/stepik_tasks/sum_num_from_last.py)
|
||||
- [sum_num_nearby](stepik/stepik_tasks/sum_num_nearby.py)
|
||||
- [Sum of squared numbers](stepik/stepik_tasks/sum_of_squared_numbers.py)
|
||||
- [Tickets](stepik/stepik_tasks/tickets.py)
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ different tasks from various courses
|
||||
- [Pie](stepik_tasks/pie.py)
|
||||
- [programmer_names](stepik_tasks/programmer_names.py)
|
||||
- [Sapper game](stepik_tasks/sapper.py)
|
||||
- [Sum of squared numbers](stepik_tasks/sum_of_squared_numbers.py)
|
||||
- [sum_num_from_last](stepik_tasks/sum_num_from_last.py)
|
||||
- [sum_num_nearby](stepik_tasks/sum_num_nearby.py)
|
||||
- [Tickets](stepik_tasks/tickets.py)
|
||||
|
@ -48,6 +48,9 @@ __*Plan of solution*__:
|
||||
- [Sum_num_nearby](sum_num_nearby.py)
|
||||
|
||||
A program that displays the sum of the right and left numbers from the main one. For the first and last numbers, the left and right numbers are the last and first numbers respectively
|
||||
- [Sum of squared numbers](sum_of_squared_numbers.py)
|
||||
A program reads numbers from the console (one per line) until their sum is equal to 0. Then it displays the sum of the squares of these numbers.
|
||||
|
||||
- [Tickets](tickets.py)
|
||||
|
||||
A program that issues a “Lucky” or "regular" ticket, the number of which we entered. If all the numbers are the same - the ticket is lucky
|
||||
|
14
practica/stepik/stepik_tasks/sum_of_squared_numbers.py
Normal file
14
practica/stepik/stepik_tasks/sum_of_squared_numbers.py
Normal file
@ -0,0 +1,14 @@
|
||||
n = int(input())
|
||||
list = [n]
|
||||
while n!= 0:
|
||||
m = int(input())
|
||||
list.append(m)
|
||||
n+=m
|
||||
sum=0
|
||||
k = [i**2 for i in list]
|
||||
for num in k:
|
||||
sum += num
|
||||
print (sum)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user