I'm currently attempting to create a program in Python that will allow a random card to be created using the random function, with a suit and the card number.
The code so far is shown below...
import random
num1 = random.randint(1,13)
num2 = random.randint(1,4)
cardnum1 = ""
cardnum2 = ""
input ("Press the enter key to continue \n")
if True:
if num1 == 11:
cardnum1 = "Queen"
elif num1 == 12:
cardnum1 = "Jack"
elif num1 == 13:
cardnum1 = "King"
elif num1 < 10:
cardnum1 = num1
elif num2 == 1:
cardnum2 = "Spades"
elif num2 == 2:
cardnum2 = "Hearts"
elif num2 == 3:
cardnum2 = "Diamonds"
elif num2 == 4:
cardnum2 = "Clubs"
print (cardnum1, cardnum2)
If the card number (num1) is 11, 12 or 13, the card will be Jack, Queen and King respectively. If the variable num22 is equal to 1, 2, 3 or 4, the card will be Spades, Hearts, Diamonds and Clubs respectively too.
The issue I have here is that rather than having both the card number and its suit printed together, the IDLE only prints the card number and chooses not to print the variable cardnum2. For example, if num1 is 8 and num2 is Diamonds, I would expect the IDLE to print "9 Diamonds" but instead prints only "9". I can only choose this method to solving and writing the program, so can someone please help clear the code and help me with this code?
Thanks, Jack.
UPDATE: Can I just ask, how can I loop the program so that it repeatedly creates new cards when the user presses the enter key?
if True:? - jabaldonedoif True:line and unindent the block below it. - jwodder