-
Notifications
You must be signed in to change notification settings - Fork 14
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
Homework9: Aniskevich Valerij #136
Open
Valery1995
wants to merge
3
commits into
AlekseyQty:main
Choose a base branch
from
Valery1995:homework9
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 1.Библиотека | ||
# Создайте класс book с именем книги, автором, кол-м страниц, ISBN, флагом, | ||
# зарезервирована ли книги или нет. Создайте класс пользователь который может брать | ||
# книгу, возвращать, бронировать. Если другой пользователь хочет взять | ||
# зарезервированную книгу(или которую уже кто-то читает - надо ему про это сказать). | ||
|
||
class Book: | ||
|
||
def __init__(self, reserded=False): | ||
self.name_book = "Motivation" | ||
self.author = "Brain Tracy" | ||
self.pages = 144 | ||
self.isbn = 9785000571002 | ||
self.reserved = reserded | ||
|
||
|
||
class User: | ||
def take(self, book): | ||
if book.reserved == False: | ||
name_user = input("Введите своё имя \n") | ||
self.name_user = name_user | ||
self.book = book | ||
book.reserved = True | ||
print(f"{self.name_user}, книга '{book.name_book}' взята успешно!") | ||
else: | ||
print("Извините, книга забронирована") | ||
|
||
def to_return(self, book): | ||
book.reserved = False | ||
print(f"Книга '{book.name_book}' возвращена! Спасибо!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Добавь имя пользователя в параметр класса и инициализируй его в методе init(). Зачем каждый раз когда берем книгу спрашивать имя пользователя, ведь пользователей может быть несколько и имя у них меняться не будет |
||
|
||
|
||
|
||
motivation = Book() | ||
user = User() | ||
user.take(motivation) | ||
user.to_return(motivation) | ||
user2 = User() | ||
user2.take(motivation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 2.Банковский вклад | ||
# Создайте класс инвестиция. Который содержит необходимые поля и методы, например | ||
# сумма инвестиция и его срок. | ||
# Пользователь делает инвестиция в размере N рублей сроком на R лет под 10% годовых | ||
# (инвестиция с возможностью ежемесячной капитализации - это означает, что проценты | ||
# прибавляются к сумме инвестиции ежемесячно). | ||
# Написать класс Bank, метод deposit принимает аргументы N и R, и возвращает сумму, | ||
# которая будет на счету пользователя. | ||
class Investment: | ||
def __init__(self, sum, term): | ||
self.sum = sum | ||
self.term = term | ||
|
||
|
||
class Bank: | ||
def deposit(self, investment): | ||
self.sum = investment.sum | ||
self.term = investment.term | ||
for i in range(self.term*12): | ||
self.sum = self.sum + self.sum*0.10/12 | ||
self.income = int(self.sum) | ||
print(f"Your investment:{investment.sum}$ will make a profit:{self.income}$ in {self.term} years ") | ||
|
||
|
||
valera = Investment(3000, 6) | ||
investment = Bank() | ||
investment.deposit(valera) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тебе нужно в методе init инициализировать новую книгу, все значения которой можно будет передать в констркутор класса.
Сейчас твой класс Book может содержать только одну книгу.
Переделеай все поля класса также, как ты сделал с параметром self.reserved, т.е передавай их в конструктор класса.