Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 3 #1806

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# IPython Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject
### VirtualEnv template
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
pyvenv.cfg
.venv
pip-selfcheck.json

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# idea folder, uncomment if you don't need it
# .idea
14 changes: 14 additions & 0 deletions Урок 3. Практическое задание/task_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,17 @@

Process finished with exit code 0
"""


def division(first, second):
res = first / second
return res


a = int(input("Введите делимое: "))
b = int(input("Введите делитель: "))

try:
print(division(a, b))
except ZeroDivisionError:
print("Вы что? Пытаетесь делить на 0!")
8 changes: 8 additions & 0 deletions Урок 3. Практическое задание/task_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
Иван Иванов 1846 года рождения, проживает в городе Москва,
email: [email protected], телефон: 01005321456
"""


def to_print(name, surname, year, city, email, phone):
return f"{name} {surname} {year} года рождения, проживает в городе {city}, email: {email}, телефон: {phone}"


creds = input("Введите данные о пользователе через пробел: ").split()
print(to_print(phone=creds[5], name=creds[0], surname=creds[1], year=creds[2], city=creds[3], email=creds[4]))
13 changes: 13 additions & 0 deletions Урок 3. Практическое задание/task_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,16 @@
1) используя функцию sort()
2) без функции sort()
"""


def my_func(a, b, c):
nums = [a, b, c]
nums.sort()
nosort = (((f"{c + a}", f"{c + b}")[b > a], (f"{b + c}", f"{b + a}")[a > c])[b > c],
((f"{c + b}", f"{c + a}")[a > b], (f"{a + c}", f"{a + b}")[b > c])[a > c])[a > b]
# Данную задачу можно было решить без нечитаемого тернарного оператора, но я очень захотел сделать через тернарник
# Простите :(
return f'Используя функцию sort(): {nums[2] + nums[1]}\nБез функции sort(): {nosort}'


print(my_func(*[int(i) for i in input("Введите 3 числа через пробел: ").split()]))
15 changes: 15 additions & 0 deletions Урок 3. Практическое задание/task_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@
ВНИМАНИЕ: использование встроенной функции = задание не принято
Постараться придумать свой алгоритм без **
"""


def my_func(x, y):
result = x
if y == 0:
return 1
for i in range(-y - 1):
result = result * x
return 1 / result


x = int(input("Введите число: "))
power = int(input("Введите степень: "))
print(my_func(x, power))

16 changes: 16 additions & 0 deletions Урок 3. Практическое задание/task_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
символ введен после нескольких чисел, то вначале нужно добавить сумму этих чисел к полученной
ранее сумме и после этого завершить программу.
"""


def my_func():
result = 0
while True:
for i in input("Введите целые числа через пробел: ").split():
if i == "*":
print(result)
print("Остановка")
return
else:
result = result + int(i)
print(result)


my_func()
8 changes: 8 additions & 0 deletions Урок 3. Практическое задание/task_6.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
Сделать вывод исходной строки, но каждое слово должно начинаться с заглавной буквы.
Необходимо использовать написанную ранее функцию int_func().
"""


def int_func(text):
return text.title()


for i in input("Введите слова через пробел ").split():
print(int_func(i), end=" ")