Computer shop


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<In what way does your code behave incorrectly? Include ALL error messages.>
I would like to make a boolean flag in this program that will help in the tracking of stock levels. If the components are in stock, then one of the components has to taken off the stock level. However if there is no particular component in stock it must produce an error message and start the program all over again.
It must all use a unique estimate number each time the program runs along with the details of the customer and the date of the order have to be input. Two copies of the order have to be printed, with a summary of the days orders.
<What do you expect to happen instead?>

```python
def getProcessor():
    print("Processor")
    print("Option 1 - p3 $100")
    print("Option 2 - p5 $120")
    print("Option 3 - p7 $200")
    option = int(input("Please choose an option: "))
    #Validation
    while (option < 1 or option > 3):
        print("Invalid option")
        option = int(input("Please choose an option (1-3): "))
    #Calculate cost
    if option == 1:
        total = 100.00
    elif option == 2:
        total = 120.00
    else:
        total = 200.00
    return total

def getRam():
    print("RAM")
    print("Option 1 - 16GB $75")
    print("Option 2 - 32GB $150")
    option = int(input("Please choose an option: "))
    #Validation
    while (option < 1 or option > 2):
        print("Invalid option")
        option = int(input("Please choose an option (1-2):  "))
    #Calculate cost
    if option == 1:
        total = 75.00
    else:
        total = 150.00
    return total

def getStorage():
    print("Storage")
    print("Option 1 - 1TB $50")
    print("Option 2 - 2TB $100")
    option = int(input("Please choose an option:  "))
    #Validation
    while (option < 1 or option > 2):
        print("Invalid option")
        option = int(input("Please choose an option (1-2): "))
    #Calculate cost
    if option == 1:
        total = 50.00
    else:
        total = 100.00
    return total

def getScreen():
    print("Option 1 - 19' $65")
    print("Option 2 - 23' $ 120")
    option = int(input("Please choose an option:  "))
    #Validation
    while (option < 1 or option > 2):
        print("Invalid option")
        option = int(input("Please choose an option (1-2):  "))
    #Calculate cost
    if option == 1:
        total = 65.00
    else:
        total = 120.00
    return total

def getCase():
    print("Option 1 - Mini Tower $40")
    print("Option 2 - Midi Tower $70")
    option = int(input("Please choose an option:  "))
    # Validation
    while (option < 1 or option > 2):
        print("Invalid option")
        option = int(input("Please choose an option (1-2):  "))
    # Calculate cost
    if option == 1:
        total = 40.00
    else:
        total = 70.00
    return total

def getUSBports():
    print("Option 1 - 2 ports $10")
    print("Option 2 - 4 ports $20")
    option = int(input("Please choose an option:  "))
    # Validation
    while (option < 1 or option > 2):
        print("Invalid option")
        option = int(input("Please choose an option (1-2):  "))
    # Calculate cost
    if option == 1:
        total = 10.00
    else:
        total = 20.00
    return total


#MAIN
total = 0.00
print("COMPUTER SHOP")
print("Select components to make your custom computer")
total = total + getProcessor()
total = total + getRam()
total = total + getStorage()
total = total + getScreen()
total = total + getCase()
total = total + getUSBports()
total = total * 1.2
print("The total is $" + str(total))

inStock = True
stock_levels = True
stocklevels_Processor_p3 = 5
stocklevels_Processor_p5 = 5
stocklevels_Processor_p7 = 5
stocklevels_Ram_16GB = 8
stocklevels_Ram_32GB = 8
stocklevels_Storage_1TB = 8
stocklevels_Storage_2TB = 8
stocklevels_Screen_19 = 4
stocklevels_Screen_23 = 2
stocklevels_Case_MiniTower = 6
stocklevels_Case_MidiTower = 6
stocklevels_USBports_2ports = 4
stocklevels_USBports_4ports = 6
<do not remove the three backticks above>

#2

that sounds like a good challenge, have fun :slight_smile:

I don’t see a question anywhere, is there anything we could help with?

I could recommend using multi-line string for print:

print("""line1
line2
line3""")

its neater.


#3

What about indentation? :confused:

How would you do this:

for _ in range(2):
    print(
        'blahblah\n'
        'blahblah\n'
        'blahblah'
    )

for _ in range(2):
    print('''\
blahblah
blahblah
blahblah\
''')

#4
    print("""
         indention is just fine 
    """)

i can perfectly make suggestions


#5

It’s not! It’ll get included in the string


#6

Do you need to full question typed? I need help with setting up the boolean flag that will subtract one component if its selected, however if the boolean flag is false then it prints out a error message and restarts the code all over again.


#7

this is currently not possible, given the script only runs once, so you won’t run out of stock. (stocks are redefined when script runs again)

so you will first need to create a way, to persist purchases. Depending on how this is implemented, we can work on your boolean flag (whatever flag means in this case)