I am trying to get the margin of two items in an array, the array consists of 4 float values each, and I want the first array item to be subtracted by the first array item in the second array, and so on for the rest of the array.
My current code looks like this:
buyPrice = [
'456.3',
'2346.5',
'123.5',
'43.5',
]
sellPrice = [
'426.3',
'1346.5',
'23.5',
'13.5',
]
total = 0
amount = 0
userInput = int(input("How much coins do you want to spend?: "))
for x in buyPrice:
while total <= userInput:
total += float(x)
amount += 1
for y in sellPrice:
k = float(x) - float(y)
print("Profit: " + str(k))
print("Total Cost: " + str("{:.1f}".format(total)))
print("Buy: " + str(amount))
print("----------")
amount = 0
total = 0
k = 0
And the MARGIN output is this:
Item 1: -382.8
Item 2: -1303,0
Item 3: 20
Item 4: 30.0
Output should be:
Item 1: 30
Item 2: 1000
Item 3: 100
Item 4: 30
I think my other code is interrupting this, as I am trying to get: 1. Total amount of items I can buy with the user Input (product price: 10k - userInput = 100k - total amount of items that can be bought: 10 - and so on) 2. The profit the user can make if they are selling the item for a higher price. 3. The total cost of buying all the products (total = buyprice + buyprice)
I could just be completely of right now, it is early in the morning, but I am completely lost.
EDIT: After some debugging on this I see that "X" never changed value, it kept being "426.3", most likely because of my for loop? How can I fix that?
Thanks