Python Forum
Can someone help me alter/complete my python 3.7 code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Can someone help me alter/complete my python 3.7 code (/thread-14276.html)



Can someone help me alter/complete my python 3.7 code - kathyadventure94 - Nov-22-2018

Please can someone tell me the faults and how to fix them Angel

#Celebrity Dog Games
"""
The progam is a similar to the card game 'Trump Card' Where the players compare cards to see which chosen value is higher than their opponents. The aim of the program is to allow the user to play the game agaisnt the computer
and that the cards generated are placed into arrays and hopefully have it choose a random name that hasn't been used.
"""
import random 
print ("Welcome to Celebrity Dog Game!")
print ("Please Select an Option: ")
print ("                      ")
menu = int(input ('1 - Play Game  2 - Quit'))

 
y = 0
playerspile = 0
computerpile = 0
 
cardchoice = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
multiple2 = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]
 
if menu == 2:
    print("Goodbye, please come again!")
    raise SystemExit
elif menu == 1:
    print("Lets Play!")
    
           

print("Please enter an even number between 4 and 30.")
pilenumber=int(input("Number of cards: ")) #Ask the users to imput their wanted Pile Size
 
if pilenumber < 4 and pilenumber >= 30:
    print("Please select a number between 4 to 30.") #Tells the user that the number is not between 4 and 30.
             
elif pilenumber not in multiple2:
    print("Please select a number which can be divided by 2.") #Tells the user that the number is not a multiple of two.
 
elif pilenumber not in cardchoice:
    print("You must enter a number") #Tells the user that the input is not a number


with open('dogs.txt') as cards: # Open file on read mode
    dogname = cards.read().split("\n") # Create a list containing all lines
    dogname = [dogname.split(",") for line in cards] #This splits the list into arrays
    cards.close()
            
     
    #Anything between this message to the next message generates the value for both the player's and the computer's first and other cards
    middle = pilenumber / 2 
    playerdeck =[0,middle-1]
    computerdeck = [middle,pilenumber]
    plength = len(playerdeck)
    clength = len(computerdeck)
 
    #Here should be a line of code to select a name from the created array.
                
    p_excercise = random.randint(1,5) 
    p_intelligence = random.randint(1,100)
    p_friendliness = random.randint(1,10)
    p_drool = random.randint(1,10)
 
    c_excercise = random.randint(1,5) 
    c_intelligence = random.randint(1,100)
    c_friendliness = random.randint(1,10)
    c_drool = random.randint(1,10)
    
#Beyond this point is where the game begins.
while y == 0:
    print("You have: ", plength, "Cards") #Prints out the player's card
    print("The Computer has: ",clength, " Cards")#Prints out the computer's deck size
                
    print("Your dog name is: " + str(dogname))
    print("Your categories are : " " Excercise: " + str(p_excercise) + "   Friendliness: " + str(p_friendliness) + "   Intelligence: " + str(p_intelligence) + "   Drool: " + str(p_drool))#Prints out the player's first card
    categorychoice = int(input("Please select a category you wish to compare: 1-Excerise 2-Friendliness 3-Intelligence 4-Drool "))
    choice = int(input(categorychoice))
            
    #Beneath this code is where the Chosen Category is being compared with the computer's card.
    if category == 1:
        print("You've chosen to compare your Excerise.")
                            
    if c_excercise > p_excercise:
        print("Computer wins!")
        playerdeck = playerdeck - 1
        computerdeck = computerdeck + 1
        cardgeneration()
                
    elif c_excercise <= p_excercise:
        print("Player wins!")
        playerdeck = playerdeck + 1
        computerdeck = computerdeck - 1
        cardgeneration()
                
    elif category == 2:
        print("You've chosen to compare your Friendliness.")
        if c_friendliness > p_friendliness:
            print("Computer wins!")
            playerdeck = playerdeck - 1
            computerdeck = computerdeck + 1
            cardgeneration()
                
        elif c_friendliness <= p_friendliness:
            print("Player wins!")
            playerdeck = playerdeck + 1
            computerdeck = computerdeck - 1
            cardgeneration()
                
        elif category == 3:
            print("You've chosen to compare your Intelligence.")
            if c_intelligence > p_intelligence:
                print("Computer wins!")
                playerdeck = playerdeck - 1
                computerdeck = computerdeck + 1
                cardgeneration()
                
        elif c_intelligence <= p_intelligence:
                print("Player wins!")
                playerdeck = playerdeck + 1
                computerdeck = computerdeck - 1            
                cardgeneration()
                
        elif category == 4:
            print("You've chosen to compare your Drool.")
            if c_drool > p_drool:
                print("Player wins!")
                playerdeck = playerdeck + 1
                computerdeck = computerdeck - 1
                cardgeneration()
                
        elif c_drool <= p_drool:
            print("Computer wins!")
            playerdeck = playerdeck - 1
            computerdeck = computerdeck + 1
            cardgeneration()
                
        if playerdeck == pilenumber:
            print("Player wins the game!")
            y = 1
            leave()
        elif computerdeck == pilenumber:
            print("Computer wins the game!")
            y = 1
            
             

#The player is given the option if they wish to play again or end the code by changing the 'a' variable to 1
leave = input(("Would you like to play again or leave the game?"))
                
if (leave == Y or leave == Y):
    print("Please come again!")
    raise SystemExit #Stops the whole code
elif (leave == N or leave == n):
    print("Returning to main menu.")
    menu() #Returns to the main menu



RE: Can someone help me alter/complete my python 3.7 code - ichabod801 - Nov-22-2018

You need to put the python tags around your code, not both of them before it. Here are instructions on how to do it right.

We don't like doing all the work around here. You tell us what the problems are, and we'll help you fix them.