I want to display the last element of a random number.
I want to create something like a life game using random.randint.
But in the following, what method is used for "step"
I don't know how to display "Random numbers from last rolling dice".
There was an instruction such as "-1" for index, but I don't know how to specify it.
↓ (quoted text)
On each iteration, set step equal to the last element in the random_walk list.You can use the index -1 for this.
# Numpy is imported, seed is set # Initialize random_walk random_walk =  # Complete the ___ for x in range (100): # Set step: last element in random_walk step = random_walk [-1] # Roll the dice dice = np.random.randint (1,7) # Determine next step if dice<= 2: step = step-1 elif dice<= 5: step = step + 1 else: step = step + np.random.randint (1,7) # append next_step to random_walk random_walk.append (step) # Print random_walk print (random_walk)
Answer # 1
In Python, you can specify an element from the right side by specifying a negative index.
>>>lst = ['s', 'p', 'a', 'm'] >>>lst [-1] 'm' >>>lst [-2] 'a' >>>lst [-3] 'p' >>>lst [-4] 's'
- i want to display a one-dimensional vector from the number entered with the python keyboard to 0
- how to multiply each element by a number in a python 2d list
- [python3] i want to display the numerical list from excel vertically (line feed display) on the tkinter window
- python - i want to display a graph of matplotlib on tkinter and enable mouse operation in canvas
- python 3x - i want to display folium immediately using the tempfile library without outputting it to html
- i want to input an element and extract one element using the python3 library openpyxl
- css - i want to display the pseudo element after
- set python excel serial number to date and time
- html - [css] i want to display absolute in the parent element
- i want to display python3 when executing python --version on centos7
- how to align the number of elements with overlaplengt of python etc
- get the total number and name of python grouping
- python - the table element generated by the django template variable is output at the bottom of the page
- python - i want to display the my page button only to users who have logged in with django, but there is a problem
- get the number of characters from the python text box
- i want to invert the number 12345 in python like 54321 and display it
- i want to change the display of the weather forecast python weather api
- python 3x - i want to display a japanese map using japanmap, but i can't no error
- python - i want to divide a binary number into two, store it in a list, and represent it in a different decimal number
- python - how to display a list using curly braces
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- python 3x - typeerror: 'method' object is not subscriptable
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- i want to call a child component method from a parent in vuejs