Though it needs some organizational cleanup(am new to python, still improving, feel free to give all suggestions/critique), I'm not sure why the conditional block is returning 'pack1' to bestValueNamed when it should only do that when it is > either one of the two(in this case it is not: see test values).
Section in question is between double asterisks(not sure if it will make it bold). Thanks in advance. :)
The test values I used were:
totalCardsInSet: 8
listOfCardValues: [1, 2, 3, 4, 5, 6, 7, 8]
pack1Cards: [1, 2]
pack2Cards: [3, 4]
pack3Cards: [5, 6]
And here's the code:
setOfCards = []
listOfCardValues = []
totalCardsInSet = int(input("How many total cards in the set?\n> "))
print("List each value, in order of card number, in cents, 1 per line.")
index = 0
for card in range(totalCardsInSet):
value = int(input("> "))
listOfCardValues.append(value)
setOfCards.append(index)
index += 1
print(setOfCards)
print(listOfCardValues)
pack1Cards = []
pack2Cards = []
pack3Cards = []
cardsInPack = int(input("How many cards in a pack?\n> "))
for packNo in range(0, 3):
print(f"Input the card values in pack {packNo + 1}")
if packNo == 0:
for cardVal in range(0, cardsInPack):
pack1Input = int(input("> "))
pack1Cards.append(pack1Input)
elif packNo == 1:
for cardVal in range(0, cardsInPack):
pack2Input = int(input("> "))
pack2Cards.append(pack2Input)
else:
for cardVal in range(0, cardsInPack):
pack3Input = int(input("> "))
pack3Cards.append(pack3Input)
print(pack1Cards)
print(pack2Cards)
print(pack3Cards)
packValues = {
'sum1': sum(pack1Cards),
'sum2': sum(pack2Cards),
'sum3': sum(pack3Cards),
}
**
bestValueNamed = []
bestValue = []
if packValues['sum1'] > packValues['sum2'] or packValues['sum3']:
bestValueNamed.append('pack 1')
bestValue.append(packValues['sum1'])
if packValues['sum2'] > packValues['sum3']:
bestValueNamed.append('pack 2')
bestValue.append(packValues['sum2'])
else:
bestValueNamed.append('pack 3')
bestValue.append(packValues['sum3'])
else:
bestValueNamed.extend(['pack 2', 'pack3'])
bestValue.extend([packValues['sum2'], packValues['sum3']])
**
print(bestValueNamed)
print(packValues['sum1'])
print(packValues['sum2'])
print(packValues['sum3'])
print(f"The two packs with most value are {bestValueNamed[0]} and {bestValueNamed[1]} worth {sum(bestValue)} cents.")
cardValSum = sum(listOfCardValues)
print(f"The total value of all three packs is {cardValSum}.")