Reputation: 13
I have been working on some code within python, and im trying to have a end="" print out a whole list on the same line. the list will then receive more values and delete the old ones. i want these new values to be printed on a new line, and i want to print the whole list on one line. then once again i would like the values to be deleted and new ones to be added, in a loop until all the values have been used. heres the code i wrote
def print_deck():
Deck=generate_deck()
Print_Deck=[]
j=0
if j<53:
for k in range(13):
for i in range(4):
print(Deck[j], end=" ")
j=j+1
when i run my script i get everything on one line, though im trying to only have 4 values from the list per line. here is the output
king of Spades King of Clubs King of Diamonds King of Hearts Queen of Spades Queen of Clubs Queen of Diamonds Queen of Hearts Jack of Spades Jack of Clubs Jack of Diamonds Jack of Hearts Ace of Spades Ace of Clubs Ace of Diamonds Ace of Hearts 2 of Spades 2 of Clubs 2 of Diamonds 2 of Hearts 3 of Spades 3 of Clubs 3 of Diamonds 3 of Hearts 4 of Spades 4 of Clubs 4 of Diamonds 4 of Hearts 5 of Spades 5 of Clubs 5 of Diamonds 5 of Hearts 6 of Spades 6 of Clubs 6 of Diamonds 6 of Hearts 7 of Spades 7 of Clubs 7 of Diamonds 7 of Hearts 8 of Spades 8 of Clubs 8 of Diamonds 8 of Hearts 9 of Spades 9 of Clubs 9 of Diamonds 9 of Hearts 10 of Spades 10 of Clubs 10 of Diamonds 10 of Hearts
I would like it like this:
king of Spades King of Clubs King of Diamonds King of Hearts
Queen of Spades Queen of Clubs Queen of Diamonds Queen of Hearts
Jack of Spades Jack of Clubs Jack of Diamonds Jack of Hearts
Ace of Spades Ace of Clubs Ace of Diamonds Ace of Hearts
ect ect
Any help would be amazing, ive been sitting here for the past 4 hours trying to figure this out.
Upvotes: 0
Views: 146
Reputation: 144
I think what you wanted was something like this:
def print_deck():
Deck=generate_deck()
Print_Deck=[]
j=0
for k in range(13):
for i in range(4):
print(Deck[j], end=" ")
j=j+1
print(" ")
also the if j < 53:
is unneccessary as the previous line sets j
value to zero
Upvotes: 1