#๐ Inheritance & Polymorphism: Errors passing variables
8 messages ยท Page 1 of 1 (latest)
@velvet wolf
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Lab12P1b.py reads as follows (item_type commented out for debugging):
from inventory_item import InventoryItem as Inv
from book import Book
from game import Game
from dvd import DVD
def main():
string_list = []
for x in range(3):
# item_type = input('Enter item type (1-Book, 2-Game, 3-DVD): ')
item_type = "1"
if item_type == "1":
Book.get_item_input(x)
string = Book.__str__
string_list.append(string)
else:
print(f'Input "{item_type}" not valid.')
x = x-1
print(f'{string_list[0]}\n{string_list[1]}\n{string_list[2]}')```
book.py reads as follows:
```python
from inventory_item import InventoryItem as Inv
class Book(Inv):
isbn13 = ""
def __init__(book, name, count, cost, isbn13):
super().__init__(book, name, count, cost)
category = "Book"
book.__name = name
book.__count = count
book.__cost = cost
book.__category = category
book.__isbn13 = isbn13
def get_item_input(book):
Inv.get_item_input(book)
# get the isbn
while True:
isbn13 = input('Enter the ISBN number: ')
if len(isbn13) != 13:
print('ISBN contains 13 characters.')
elif not isbn13.isdigit():
print('ISBN number must be all digits.')
else:
break
book.__name = book.item_name
book.__count = book.count
book.__cost = book.cost
book.__isbn13 = isbn13```
problems passing variables between classes?
I feel like there should be a return in InventoryItem.get_item_input() but there isn't one and I'm told the code should be working correctly as-is
@velvet wolf
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ problems passing variables between classes?
@velvet wolf
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.