Cyqix Cyqix - 8 days ago 8
Python Question

How can I make this addition method simpler?

This code adds a set of cards (in a game of blackjack)

# Rules
print("Dont enter Ace, Jack, Queen or king in the first 4 Inputs")
print("You will be told when to enter those")
print("if you dont have a card just enter 0")

# Line break
print("")

card1 = int(input("What is your first card: "))
card2 = int(input("What is your second card: "))
card3 = int(input("What is your third card: "))
card4 = int(input("What is your fourth card: "))


# Line break
print("")

# print("King = 10 \nJack = 10 \nQueen = 10 \nAce = 11 or 1 ")
AJKQ = (input("Any Ace, jack, Queens or kings: "))
AJKQ2 = (input("Any Ace, jack, Queens or kings: "))

# Line Break
print("")

print(card1 + card2 + card3 + card4 + AJKQ + AJKQ2)


The code needs to add up the cards the user has and output them with Ace, jack queen and king

Im also not great with ifs and elifs, so whats the best way to compress this to smaller code?

Answer
print("""Dont enter Ace, Jack, Queen or king in the first 4 Inputs
You will be told when to enter those.
if you dont have a card just enter 0\n""")

print(sum([int(input("what is your "+ char +" card: ")) for char in("first", "second", "third","fourth")]) +
sum([int(input("Any Ace, jack, Queens or kings: ")) for i in range(0,2)]))

this should be fine.