I'm trying to print several lines to the console including variables with lengths that will change and I want to keep spacing correct and clean and easy to read. This is how I always like to write my console programs. Soon I'll to start writing with GUI's but for now this is still where I'm at. Here is where I'm at so far. It looks terrible on the code side and is not yet dynamic to the changing var lengths. I know I can rewrite it to do that but will only make it even messier and Im already having an issue running it. It works in Pycharm but when I run it in the terminal it says "SyntaxError: f-string expression part cannot include a backslash".
I'm thinking a better way is to create a list containing each line and making sure the the first half length is equal to a certain value like 40 but I'm not really sure how I can do that.
Any suggestions on the best way to go about this?
Is it going to look ugly no matter what?
Python:
# BLACKJACK SAMPLE
from random import shuffle
card_numbers = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
suits = ["hearts", "clubs", "spades", "diamonds"]
suits_abbreviated = ["H", "C", "S", "D"]
cards = [f'{card_num}-{suit}' for suit in suits_abbreviated for card_num in card_numbers]
shuffle(cards)
players_wallet = 500
dealers_wallet = 500
players_hand = []
dealers_hand = []
players_hand_value = 16
dealers_hand_value = 20
players_bid = 100
dealers_bid = 100
[players_hand.append(cards.pop()) for i in range(2)]
[dealers_hand.append(cards.pop()) for i in range(2)]
while True:
game_stats = f"""
{'\t' * 5}Your stats:{'\t' * 14}Dealer stats:
{'\t' * 4}Your hand: {players_hand}{'\t' * 9}Dealers hand: {dealers_hand}
{'\t' * 4}Your hand value: {players_hand_value}{'\t' * 11}Dealers hand value: {dealers_hand_value}
{'\t' * 4}Your wallet: ${players_wallet}{'\t' * 11}Dealers wallet: ${dealers_wallet}\n
{'\t' * 4}Your bid: ${players_bid}{'\t' * 11}Dealers Bid: ${dealers_bid}"""
print(game_stats)
players_hand.append(cards.pop())
dealers_hand.append(cards.pop())
ans = input("Press X to exit: ")
if ans.lower() == 'x':
break
I'm thinking a better way is to create a list containing each line and making sure the the first half length is equal to a certain value like 40 but I'm not really sure how I can do that.
Any suggestions on the best way to go about this?
Is it going to look ugly no matter what?
Last edited: