Every Time I run this code it doesn't work as I want it to! I'm trying to make a list of random numbers and if they are 1 digit they are replaced with ',' and 2 digits ' _,' but Whenever I do this it wont work! How Do I make this so that the numbers are replaced with underscores and everytime I choose a number this list choices the fist number on it and removes it but still keeps the same the numbers?
for Opponents_Cards1 in range(9):
Opponents_Cards1 = random.randint(0, 50)
Opponents_Deck1.append(Opponents_Cards1)
Opponents_Cards1 -= 1
for Opponents_Cards1 in Opponents_Deck1:
if(Opponents_Cards1 > 0) and (Opponents_Cards1 < 10):
print('_,'),
if(Opponents_Cards1 > 10) and (Opponents_Cards1 < 49):
print('_ _,'),
print("\nYour Opponents Deck Is,\n", Opponents_Deck1)
Opponents_Cards1 -= 1
This is the full code if you need it. It is a game I'm trying to improve:
def instructions():
print("\nThis is a card game where you get 9 cards and you have to lay down a card.\n")
print("\nYou will be playing with AI annd you will be playng 9 rounds. whoever lays down the highest number wins that round.\n")
print("\nThe points you get are determined by how much higher your card was from your AI's card.\n")
print("\nThe person with the most by round 10 points wins!\n")
def getUserInput():
print ("\nDo you want to play?: ")
print("\nChoices")
print("1. Yes")
print("2. No\n")
Choice = input()
if(Choice in ['Yes', 'yes']):
print("Okay, choose your mode!")
elif(Choice in ['No', 'no']):
print("Okay, bye!")
else:
print("That is not a Choice!")
print("Choose 'Yes' or 'No'")
Choose = input()
if(Choose in ['Yes', 'yes']):
print("Okay, choose your mode!")
elif(Choose in ['No', 'no']):
print("Okay, bye!")
else:
print("-_- really?")
print("\nChoices")
print("1. Easy")
print("2. Medium")
print("3. Hard\n")
import random
Choose = input()
if(Choose in ['Easy', 'easy']):
Opponents_Cards1 = random.randint(0, 50)
print("Okay, lets get started!")
startGame()
elif(Choose in ['Medium', 'medium']):
AINumber2 = random.randint(0, 75)
print("Okay, lets get started!")
startGame()
elif(Choose in ['Hard', 'hard']):
AINumber3 = random.randint(0, 100)
print("Okay, lets get started!")
startGame()
else:
print("Thats not a mode")
print("choose 'Easy', 'Medium', or 'Hard'")
Choose = input()
if(Choose in ['Easy', 'easy']):
print("Okay, lets get started!")
startGame()
elif(Choose in ['Medium', 'medium']):
print("Okay, lets get started!")
startGame()
elif(Choose in ['Hard', 'hard']):
print("Okay, lets get started!")
startGame()
else:
print("-_- really?")
def startGame():
global roundNumber, Opponents_Deck1, My_Deck, PlayerPoints, AIPoints
print("\nAIPoints = %d \nPlayerPoints = %d\n" % (AIPoints, PlayerPoints))
roundNumber += 1
print("\nRound %d!" % (roundNumber))
import random
for Opponents_Cards1 in range(9):
Opponents_Cards1 = random.randint(0, 50)
Opponents_Deck1.append(Opponents_Cards1)
Opponents_Cards1 -= 1
for Opponents_Cards1 in Opponents_Deck1:
if(Opponents_Cards1 > 0) and (Opponents_Cards1 < 10):
print('_,'),
if(Opponents_Cards1 > 10) and (Opponents_Cards1 < 49):
print('_ _,'),
print("\nYour Opponents Deck Is,\n", Opponents_Deck1)
Opponents_Cards1 -= 1
AINumber2 = random.randint(0, 75)
AINumber3 = random.randint(0, 100)
if(roundNumber == 1):
print("\nHere are your 9 cards.\n")
for Cards in range(9):
Cards = random.randint(0, 100)
My_Deck.append(Cards)
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
elif(roundNumber == 10):
if(PlayerPoints > AIPoints):
print("\nCongratulations you won!\n")
print("Your Score", PlayerPoints)
print("AI's Score", AIPoints)
getUserInput()
elif(PlayerPoints < AIPoints):
print("\nUnfortunately you lost.\n")
print("AI's Score",AIPoints)
print("Your Score",PlayerPoints)
getUserInput()
else:
print("\nWow!! What are the chances?\n")
print("Your Score",PlayerPoints)
print("AI's Score",AIPoints)
getUserInput()
else:
print("\nYou have %d card(s) left.\n" % (9 - roundNumber + 1))
while True:
print("Select one of your cards: "),
print(My_Deck)
Select = int(input())
try:
if (Select in My_Deck):
My_Deck.remove(Select)
print("You choose", Select)
print("Your deck now is:")
print(My_Deck)
cardChosen = Select
break
else:
print("You don't have that card in your deck!")
except ValueError as e:
print(e)
AINumber = Opponents_Cards1
AINumber = AINumber2
AINumber = AINumber3
cardChosen = Select
if(cardChosen > AINumber):
print("\nYou won that round! Your card number %d was higher than the AI's card number %d" % (cardChosen, AINumber))
print("\nYou scored %d points" % (cardChosen - AINumber))
PlayerPoints = PlayerPoints + (cardChosen - AINumber)
startGame()
elif(cardChosen < AINumber):
print("\nYou Lost that round! Your card number %d was lower than the AI's card number %d" % (cardChosen, AINumber))
print("\nAI scored %d points" % (AINumber - cardChosen))
AIPoints = AIPoints + (AINumber - cardChosen)
startGame()
elif(cardChosen == AINumber):
print("\nYou tied with the AI! Your card number %d was the same as the AI's card number %d" % (cardChosen, AINumber))
print("\nNobody scored points!")
AIPoints = 0
PlayerPoints = 0
startGame()
Opponents_Deck1 = []
My_Deck = []
roundNumber = 0
AIPoints = 0
PlayerPoints = 0
instructions()
getUserInput()
Thank you
Aucun commentaire:
Enregistrer un commentaire