I've been trying to make a program for a card game, a quick summary: Write a python script to create a random card, representing the card as a tuple, storing the card value and the color.
One of the conditions was that whilst I loop 3 times, I have to make sure that each card does not have the same values and color as the rest so that no 2 cards are the same. (When the second card is created, check if it is the same as the first and if it is, try again.
When the third card is created, check if it is the same as the first OR the second and if it is, try again.)
I would then have to create a function that adds together the value of 3 cards and returns the sum.
Of course, there is more to it than that but my question is a simple one. So far what I've done:
import random
num = random.randint(0,9)
colour = random.choice(["red", "green", "blue", "yellow"])
card = (num, colour)
def get_uno_card(card):
for _ in range(1):
print(card)
if num and colour == card:
print(card)
return card
def convert():
a = str(card)
return a
def add():
b = num * 3
return b
a = convert()
b = add()
print(get_uno_card(card))
print(a)
print(b)
This outputs:
(6, 'blue')
(6, 'blue')
(6, 'blue')
18
I have trouble trying to make sure the cards are not the same, therefore I was looking for ways to do this online and there was a post where they explained that I should use '/r'. I haven't come across this and don't know how I should use this in this scenario, or if I should use it at all.
Could someone explain how I could check if the 3 tuples are the same and if they are, how would I generate another card in its place?