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 7750809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:23:12+00:00 2026-06-01T11:23:12+00:00

I have 10 dice that are all programmed the same as D1. D1 =

  • 0

I have 10 dice that are all programmed the same as D1.

D1 = random.randint(1,12)

I then store them all in a list like this:

roller[DI,D2...]

A person then selects the die to keep (in a while loop) and when he wants to roll the remaining dice he ends the loop. The program below successfully loops, however the dice in the list are not changing. What am I missing?

 while wanted != "11":
        print("The dice left in your roll:" , roller)
        want = int(input("Select Di by using numbers 0-9.")) 
        di = roller[want]
        del roller [want]
        keep.append(di)
        print("Dice that you have kept:" , keep)
        wanted = input("\nType 11 to roll again. Type anything else to select more dice.\n")
        wanted = "12"
        D1 = random.randint(1,12)
        [... more setting ...]
        D10 = random.randint(1,12)

However, after setting the dices D1 through D10, the next iteration of my while loop does not reflect a change of value for the roller list. Why is this?

  • 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-01T11:23:14+00:00Added an answer on June 1, 2026 at 11:23 am

    Changing D1 won’t change the die in the list. You have to change the value in the list itself.

    >>> import random
    >>> dices = [random.randint(1,12) for i in range(0,10)]
    >>> dices
    [5, 2, 1, 6, 4, 8, 4, 10, 1, 10]
    >>> dices[1] = random.randint(1,12)
    >>> dices
    [5, 5, 1, 6, 4, 8, 4, 10, 1, 10]
    

    Note above how the second dice (index 1) has changed value in the dices list.

    Ie, instead of Dn = random.randint(1,12) where n is your dice, you want to do dices[n] = random.randint(1,12)

    More generally, you misunderstand the assignment operator in python.

    >>> f = 123
    

    Sets ‘f’ to point to the value ‘123’.

    If you put f in a list, like this:

    >>> my_list = [f, 1, 2, 3]
    

    What you are doing is saying: “create a list, named ‘my_list’ that has a reference to the value 123, 1, 2 and 3 in it.

    When you reassign to ‘f’, the reference in the list does not change.

    >>> f = 456
    >>> my_list
    [123, 1, 2, 3]
    

    What you’re saying is “now f points to the value 456”. This does not chnge the meaning of what was put in your list.

    [aside]: Interestingly, while this is the case for Python, this is not true of all languages.

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

Sidebar

Related Questions

I have a program that generates/'rolls' two dice. I would like to output these
I have a little shader that looks like this, and has a neat effect.
I have an assignment that simulates a dice game. As part of the program,
I'm creating a usercontrol that will have a series of LinkButtons. I've declared all
I have this code for a simple Dice throwing program with betting units and
I'm making a dice game. There are 5 dice in which I have all
I have a table that gets a dynamic source list for each row, with
This question is about guaranteeing all arguments are of the same type while exhibiting
A friend of mine asked: if I have two dice and I throw both
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css

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.