Basically, I'm trying to create a program that will replace the values of diceList with a random integer between 1 and 6 wherever my indexList has a 1 in it. This is what I have so far:
import random
def replaceValues(diceList, indexList):newList = diceListfor i in indexList:if indexList == 1:newList[i] = random.randint(1,6)return newList
I'm executing replaceValues([1,2,3,4,5], [0,1,0,1,0]) and what I should get is [1,x,3,x,5] where x should be a random number between 1 and 6. The problem is it currently returns [1,2,3,4,5]
Answer
Is indexList a list? If so, what does a list == 1 mean?
if indexList == 1:newList[i] = random.randint(1,6)
Lately Ive been requested to run a python script on my Azure Release Pipeline.
This script needs some environment variables for being executed, as Ive seen that in the build pipeline, the task include …
File C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\mysql\connector\cursor.py, line 1149, in execute elif len(self._prepared[parameters]) != len(params): TypeError: object of ty…
Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 6 years ago.Improve…
This is the file: https://drive.google.com/file/d/0B5v-nJeoVouHc25wTGdqaDV1WW8/view?usp=sharingAs you can see, there are duplicates in the first column, but if I were to combine the duplicate rows, no…
I have loaded a csv file and as i try to print it i get this error
Traceback (most recent call last):File "C:\Users\FSTC\Downloads\spaceproject\main.py", line 389, in <module>world_data…
Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 1…
So I have a list where each entry looks something like this:
"{A: array([1]), B: array([2]), C: array([3])}"I am trying to get a dataframe that looks like thisA B C
0 1 2 3
1 4 …
I am trying to make a button in Maya using Python that when you type in a number the for loop would loop for that many times. For example, I would put 5 in the box so the for loop would loop 5 times re…
I utf-8 encode characters like \u2013 before inserting them into SQLite.When I pull them out with a SELECT, they are back in their unencoded form, so I need to re-encode them if I want to do anything w…
I am making a live plotter to show the analog changes from an Arduino Sensor. The Arduino prints a value to the serial with a Baudrate of 9600. The Python code looks as following: import matplotlib.pyp…