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

  • SEARCH
  • Home
  • 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 8471573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:50:01+00:00 2026-06-10T16:50:01+00:00

Hi you might remember this program if you are a regular here. I have

  • 0

Hi you might remember this program if you are a regular here. I have solved many of the bugs but am stumped by one. The error is:

File "/Users/administrator/Desktop/war.py", line 62, in <module>
    player1.extend(player1[range(warcardvalue1)])
TypeError: list indices must be integers, not list

the code is:

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'] 
warcardvalue0 = 0
warcardvalue1 = 0
print "shuffling cards" 
random.shuffle(cards)
print "lets play"

player0 = cards[1::2]

player1 = cards[::2]

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) >= 3:
                        warcard0 = player0[3]
                elif len(player0) < 3:
                    warcard0 = player0[len(player0)-1]

            if len(player1) >= 3:
                        warcard1 = player1[3]
                elif len(player1) < 3:
                    warcard1 = player1[len(player1)-1]


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

            if warcardvalue0 > warcardvalue1:
                player0.extend(player0[range(warcardvalue0)])
                player0.extend(player1[range(warcardvalue1)])
                player0.extend(player0[range(warcardvalue0)])
                player1.extend(player1[range(warcardvalue1)]) 

            elif warcardvalue0 < warcardvalue1:
                player1.extend(player1[range(warcardvalue1)])
                player1.extend(player0[range(warcardvalue0)])
                player1.extend(player1[range(warcardvalue1)])
                player0.extend(player0[range(warcardvalue0)]) 
            else:
                print "another war!" 


if len(player1) == 0:
    print "player1 won!"
elif len(player0) == 0:
    print "player0 won!"

I think the problem is that you cant use range in lists but I’m not sure.

  • 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-10T16:50:03+00:00Added an answer on June 10, 2026 at 4:50 pm

    I think the problem is that you cant use range in lists but I’m not sure.

    The problem is that you can’t index a list with a list.

    Try this instead:

    player1.extend(player1[:warcardvalue1])
    

    Seems a bit odd to want to do it though….

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

Sidebar

Related Questions

I'm sure I've seen this somewhere but can't remember where and it might have
So, this might be a little bit messy for me to explain, but here
This might be impossible to answer since there are probably too many variables here,
I am 90% certain I have acheived this before, but I cannot remember how
I remember hearing somewhere that large functions might have higher execution times because of
I might have a flawed understanding of what shared_examples_for should do, but hear me
This might seem like a very easy question for some of you folks, but
This is a very basic concept, but something I have never been able to
This might be a stupid question, but is there a rule that states that
This might be a stupid question, but if I'm a lone developer and only

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.