Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:59:20+00:00 2026-06-10T05:59:20+00:00

To whom this may concern, This is some code to a card game simulation.

  • 0

To whom this may concern,

This is some code to a card game simulation. (The game of war). When I run it I receive this error:

player0.append(player1[range(warcard1 + 1)] 
      ^
SyntaxError: invalid syntax

I do not have a clue what the error is but maybe someone here does. Hopefully someone can resolve the issue for me. The code is, of course, still a work in progress so if there are any other bugs i would be happy to hear about them and their possible solutions.

import random

cards = ['ace', 'ace', 'ace', 'ace', '1', '1', '1', '1', '2', '2', '2', '2', '3', '3', '3', '3', '4', '4', '4', '4', '5', '5', '5', '5', '6', '6', '6', '6', '7', '7', '7', '7', '8', '8', '8', '8', '9', '9', '9', '9', '10', '10', '10', '10', 'jack', 'jack', 'jack', 'jack', 'queen', 'queen', 'queen', 'queen', 'king', 'king', 'king', 'king']

order = ['ace', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'jack', 'queen', 'king'] 

print "shuffling cards" 
random.shuffle(cards,random.random)
print "lets play"
player0 = [cards[i] for i in range(len(cards)) if i % 2 == 1]

player1 = [cards[i] for i in range(len(cards)) if i % 2 == 0]

while (len(player0) > 0 or len(player1) > 0):

    nextcard0 = player0[0]
    nextcard1 = player1[0]

    cardplayed0 = order.index(nextcard0)

    cardplayed1 = order.index(nextcard1)

    if cardplayed0 > cardplayed1:

        player0.append(nextcard0)
        player0.append(nextcard1)
        player0.remove(nextcard0)
        player1.remove(nextcard1)

    elif cardplayed0 < cardplayed1:

        player1.append(nextcard1)
        player1.append(nextcard0)
        player1.remove(nextcard1)
        player0.remove(nextcard0)

    elif cardplayed0 == cardplayed1:
        while warcardvalue0 == warcardvalue1:
            if len(player0) >= 4:
                warcard0 = 4
            elif len(player0) < 4:
                warcard0 = len(player0)

            if len(player1) >= 4:
                warcard1 = 4
            elif len(player1) < 4:
                warcard1 = len(player1)


            warcardvalue0 = order.index(warcard0)
            warcardvalue1 = order.index(warcard1)

            if warcardvalue0 > warcardvalue1:
                player0.append(player0[range(warcard0 + 1)]
                player0.append(player1[range(warcard1 + 1)] 
                player0.remove(player0[range(warcard0 + 1)]
                player1.remove(player1[range(warcard1 + 1)] 

            elif warcardvalue0 < warcardvalue1:
                player1.append(player1[range(warcard1 + 1)]
                player1.append(player0[range(warcard0 + 1)] 
                player1.remove(player1[range(warcard1 + 1)]
                player0.remove(player0[range(warcard0 + 1)] 
            else
                print "another war!" 


if len(player1) == 0:
    print "player1 won!"
elif len(player0) == 0:
    print "player0 won!"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:59:21+00:00Added an answer on June 10, 2026 at 5:59 am

    The line indicated in the error message

    player0.append(player1[range(warcard1 + 1)] 
                                               ^
    

    is missing a closing )

    In fact all of these lines are missing the closing paren:

           if warcardvalue0 > warcardvalue1:
                player0.append(player0[range(warcard0 + 1)]
                player0.append(player1[range(warcard1 + 1)] 
                player0.remove(player0[range(warcard0 + 1)]
                player1.remove(player1[range(warcard1 + 1)] 
    
            elif warcardvalue0 < warcardvalue1:
                player1.append(player1[range(warcard1 + 1)]
                player1.append(player0[range(warcard0 + 1)] 
                player1.remove(player1[range(warcard1 + 1)]
                player0.remove(player0[range(warcard0 + 1)] 
    

    You may want to look through your code to make sure there are no other intstances of this problem.

    Also, you might consider (and certainly would benefit) from an editor that does paren matching for you, and would alert you to similar problems. I use one, and it’s definitely worth it.

    If you are interested in such editors, this might be a place to start explore options: Top 10 Best Text Editors With Brace Matching

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While I run snmpd daemon on powerpc board(a.p.) I am getting this error: R_PPC_REL24:
Given this code: $user_profile = $facebook->api('/me'); echo $user_profile['name']; I see the following error for
Im a C# developer whom is new to Objective C and this migration has
Code: $testing=sniper this and sniper that; $connectors=array('and', 'now', 'but', 'still', 'so', 'only', 'therefore', 'moreover',
I am unable to understand this error.This error is not in the class that
I am facing some critical issue which might be interesting for whom , those
To whom it may respond to , I am trying to return list of
To whom it may respond to, We would like to use SELECT function with
For this code: class B1{ public: virtual void f1() {} }; class D :
I have seen many people here on stack overflow with this error message and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.