#Help with a feature need ASAP
35 messages · Page 1 of 1 (latest)
#stock control (100)
if boxsize == '100':
current_stock = int(screw[4])
if amount > current_stock:
print('Only', current_stock, 'boxes available for this order')
answer = input('Do you want to continue with this order (Y/N)? ')
if answer.upper() == 'Y':
amount = current_stock
current_stock -= amount
screw[4] = f"{current_stock}"
total100 = float(screw[6]) * 2 * amount
if screw[7].endswith('yes'):
finaltotal100 = total100 * 0.9
print('Your total is: £',finaltotal100, '\n')
print('Your order has been placed')
else:
print('Your total is: £',total100, '\n')
print('Your order has been placed')
this is all i was able to come up with
#Listing showing screw stock details
#MATERIAL, HEAD TYPE, LENGTH, STOCK(IN BOXES OF 50,100,200), COST PER BOX of 50 (£), DISCOUNT
brass,slot,20,35,20,10,4.00, no
brass,slot,40,40,42,40,5.00, no
brass,slot,60,55,50,30,5.50, yes
brass,star,20,30,20,10,4.00, no
brass,star,40,42,33,30,5.00, no
brass,star,60,15,20,25,5.50, no
brass,pozidriv,20,20,20,10,4.00, no
brass,pozidriv,40,8,30,30,5.00, no
brass,pozidriv,60,1,20,25,5.50, no
steel,slot,20,30,30,10,3.00, no
steel,slot,40,40,30,34,4.00, no
steel,slot,60,70,50,0,4.50, no
steel,star,20,100,47,0,3.00, no
steel,star,40,19,70,5,4.00, no
steel,star,60,90,20,20,4.50, no
steel,pozidriv,20,10,40,30,3.00, no
steel,pozidriv,40,12,30,5,4.00, no
steel,pozidriv,60,25,27,20,4.50, no
this is the text file i am using
#stock control (100)
if boxsize == '100':
current_stock = int(screw[4])
if amount > current_stock:
print('Only', current_stock, 'boxes available for this order')
answer = input('Do you want to continue with this order (Y/N)? ')
if answer.upper() == 'Y':
amount = current_stock
current_stock -= amount
screw[4] = f"{current_stock}"
total100 = float(screw[6]) * 2 * amount
discount = 0.9 # Apply a 10% discount
if screw[7].endswith('yes'):
finaltotal100 = total100 * discount
print('Your total is: £',finaltotal100, '\n')
print('Your order has been placed')
else:
print('Your total is: £',total100, '\n')
print('Your order has been placed')
If you want you can use the data in the text file
# Read the data from the text file
with open('screws.txt') as f:
screws = f.readlines()
# Parse the data from the text file
screw_data = [line.strip().split(',') for line in screws]
# Loop over the screw data and calculate the total amount for each screw
for screw in screw_data:
material = screw[0]
head_type = screw[1]
length = screw[2]
stock = screw[3]
cost = screw[4]
discount = screw[5]
# Calculate the total amount
total = float(cost) * 2 * int(stock)
# Apply the discount if applicable
if screw[6].endswith('yes'):
total *= 0.9
# Print the total amount
print('The total amount for', material, head_type, length, 'screws is: £', total)
ive tried that for some reason it just executes the else statement every time
the yes in the text file means a discount applies there but it doesnt seem to work
#stock control (100)
if boxsize == '100':
current_stock = int(screw[4])
if amount > current_stock:
print('Only', current_stock, 'boxes available for this order')
answer = input('Do you want to continue with this order (Y/N)? ')
if answer.upper() == 'Y':
amount = current_stock
current_stock -= amount
screw[4] = f"{current_stock}"
total100 = float(screw[6]) * 2 * amount
discount = 0.9 # Apply a 10% discount
if screw[5].endswith('yes'):
finaltotal100 = total100 * discount
print('Your total is: £',finaltotal100, '\n')
print('Your order has been placed')
else:
print('Your total is: £',total100, '\n')
print('Your order has been placed')
i just tried this?
No
I have changed the index from screw[7] to screw[5] in the if statement to check whether the discount applies. This should fix the issue and apply the discount if the "yes" value is present in the "discount" column.
but the index screw [5] corresponds to stock of 200?
Yes your right
# Read the data from the text file
with open('screws.txt') as f:
screws = f.readlines()
# Parse the data from the text file
screw_data = [line.strip().split(',') for line in screws]
# Loop over the screw data and calculate the total amount for each screw
for screw in screw_data:
# Calculate the total amount
total = float(screw[4]) * 2 * int(screw[3])
# Apply the discount if applicable
if screw[7].endswith('yes'):
total *= 0.9
# Print the total amount
print('The total amount for', screw[0], screw[1], screw[2], 'screws is: £', total)
Idk then
bruh
wait
# Read the data from the text file
with open('screws.txt') as f:
screws = f.readlines()
# Parse the data from the text file
screw_data = [line.strip().split(',') for line in screws]
# Loop over the screw data and calculate the total amount for each screw
for screw in screw_data:
# Calculate the total amount
total = float(screw[4]) * 2 * int(screw[3])
# Apply the discount if applicable
if screw[7].endswith('yes'):
total *= 0.9
# Print the total amount
print('The total amount for', screw[0], screw[1], screw[2], 'screws is: £', total)
try it