Python Forum
Can someone help me alter/complete my python 3.7 code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone help me alter/complete my python 3.7 code
#1
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
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How would I alter this to a single api request? SuchUmami 1 751 Jun-24-2023, 08:30 AM
Last Post: ferdnyc
  Python Serial: How to read the complete line to insert to MySQL? sylar 1 831 Mar-21-2023, 10:06 PM
Last Post: deanhystad
  Python multiprocessing Pool apply async wait for process to complete sunny9495 6 6,452 Apr-02-2022, 06:31 AM
Last Post: sunny9495
  Question from complete python's newbie Davicom 3 2,378 Jun-09-2021, 06:09 PM
Last Post: bowlofred
  Python Complete novice: Want to run a vulnerability script bhanney23 1 2,993 Sep-18-2020, 09:27 AM
Last Post: Aspire2Inspire
  (Complete Novice) Code not working PythonGainz 9 4,108 Mar-21-2020, 05:53 PM
Last Post: buran
  complete newbie, trying to tweak some code notarobot 6 3,160 Nov-02-2019, 03:35 PM
Last Post: notarobot
  Best method: Python script called from another app, package as complete executable ironfelix717 2 2,145 Jul-24-2019, 07:39 AM
Last Post: DeaD_EyE
  Code does not complete sc0pe 1 2,138 Apr-09-2019, 06:05 PM
Last Post: Yoriz
  Complete Beginner Startup - Simply run github code for hpd20 Image_Engine 8 4,744 Apr-23-2018, 11:15 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020