I am currently teaching myself Python and I am currently getting indentation errors in my program. When I fix the error on line 7 and indent the line my input number_input
gets grayed out by my IDE (Pycharm community if that matters) so it is null and other errors appear after fixing the error. My program contains a class called RetailItem
in the file q05
and a main called q05_1test
. The goal of my program is that the user enters either 1, 2, or 3 and displays the corresponding output. For example when the user enters 2 the program should result in Designer Jeans (description), 40 (units), and 34.95 (price) being displayed.
File q05.py (Class)
:
class RetailItem:
def __init__(self, descr, units, price):
self.__descr = descr
self.__units = units
self.__price = price
# mutator methods
def set_descr(self, descr):
self.__descr = descr
def set_units(self, units):
self.__units
def set_price(self, price):
self.__price
# accessor methods
def show_descr(self):
return self.__descr
def show_units(self):
return self.__units
def show_price(self):
return self.__price
# set string method
def __str__(self):
return "Description: " + self.__descr + \
"\nUnits in Inventory: " + str(self.__units) + \
"\nPrice: $" + str(self.__price)
Main q05_1test
import q05.py
def main():
#user enters number that determienes what results will be displayed
number_input = input("Enter 1 for item 1 and vise versa for items 2 and 3")
items_list = []
#list
descr_list = ["Jacket", "Designer Jeans", "Shirt"]
units_list = [12, 40, 20]
price_list = [59.95, 34.95, 24.95]
for number in range(0, 4):
if number_input == 1:
for i in range(0, 3, 1):
descr = descr_list[i]
units = units_list[i]
price = price_list[i]
if number_input == 2:
for i in range(1, 3, 1):
descr = descr_list[i]
units = units_list[i]
price = price_list[i]
if number_input == 3:
for i in range(2, 3, 1):
descr = descr_list[i]
units = units_list[i]
price = price_list[i]
item = q05.RetailItem(descr, units, price)
items_list = []
items_list.append(item)
for item in items_list:
print(item)
print()
if __name__ == "__main__":
main()