'A function to assign values to some variables in Python is running, but not assigning the values
I'm trying to turn a card game I made into a Linux program in Python. The step I'm currently on is to convert the player's cards into strings based on their values. I managed to get that step working, but it broke something else: The function I used to take a list of the cards that need to be reassigned random values no longer works. When the program starts, it's supposed to assign a value to all six of the player's cards and then print their new values. However, it instead prints the default value for each card. Adding another line to print one of the cards' values as a number rather than a string shows that each card indeed still has a value of 1. I keep reading over my code, but I'm failing to figure out why the function to assign random values to the cards isn't doing anything when it did before. My code is as follows:
import sys
from os import system
from time import sleep
import random
# Variable Definitions
choosePlayer = input('Choose your player:\n[1] The Cowboy\n[2] The Hustler\n[3] The Sheriff\n[4] The Outlaw\n[5] The Barkeep\n[6] The Quarter Horse\n\nYour choice [1-6]: ')
pCard1 = 1
pCard2 = 1
pCard3 = 1
pCard4 = 1
pCard5 = 1
pCard6 = 1
playerCards = [pCard1,pCard2,pCard3,pCard4,pCard5,pCard6]
emptyVar = None
spentCards = [pCard1,pCard2,pCard3,pCard4,pCard5,pCard6]
# Function Definitions
def clear():
system('clear')
def catPlayerToStr(playerChoice):
theCat = {
1: "Cowboy",
2: "Hustler",
3: "Sheriff",
4: "Outlaw",
5: "Barkeep",
6: "Quarter Horse",
}
return theCat.get(playerChoice,"Failure to determine player")
playerChoice = int(choosePlayer)
def generateCards():
for i in range (len(spentCards)):
spentCards[i] = random.randint(1, 13)
def catCardToStr(playerCards):
for i in range (6):
theOtherCat = {
1: "Ace",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7",
8: "8",
9: "9",
10: "10",
11: "Jack",
12: "Queen",
13: "King",
}
return theOtherCat.get(playerCards,"Failure to determine card")
def listCards():
for i in range (len(playerCards)):
currentCard = catCardToStr(playerCards[i])
print(currentCard + "\n")
# Startup
clear()
print("You are the " + catPlayerToStr(playerChoice) + ". Welcome to Six-Chance Trade. Starting game in:\n3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
system('clear')
print("The " + catPlayerToStr(playerChoice) + "'s cards:")
generateCards()
listCards()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
