<jupyter_start><jupyter_text>Before, you have already written Python code that determines the next step based on the previous step. Now it's time to put this code inside a for loop so that we can simulate a random walk.<jupyter_code># Import numpy and set seed
import numpy as np
np.random.seed(123)

# Initialize random_walk
random_walk = [0]<jupyter_output><empty_output><jupyter_text>-Finish the for loop:    -The loop should run 100 times.    -On each iteration, set step equal to the last element in the random_walk list. You can use the index -1 for this.    -Next, let the if-elif-else construct update step for you.    -The code that appends step to random_walk is already coded.<jupyter_code># Complete the loop
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)<jupyter_output><empty_output><jupyter_text>Print out random_walk<jupyter_code># Print random_walk
print(random_walk)<jupyter_output>[0, 3, 4, 5, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, -1, 0, 5, 4, 3, 4, 3, 4, 5, 6, 7, 8, 7, 8, 7, 8, 9, 10, 11, 10, 14, 15, 14, 15, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 32, 33, 37, 38, 37, 38, 39, 38, 39, 40, 42, 43, 44, 43, 42, 43, 44, 43, 42, 43, 44, 46, 45, 44, 45, 44, 45, 46, 47, 49, 48, 49, 50, 51, 52, 53, 52, 51, 52, 51, 52, 53, 52, 55, 56, 57, 58, 57, 58, 59]
{'fraction_non_alphanumeric': 0.12360248447204969, 'fraction_numerical': 0.11801242236024845, 'mean_word_length': 3.3423180592991915, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '246194', 'license': 'MIT', 'n_tokens_mistral': 776, 'n_tokens_neox': 585, 'n_words': 249, 'path': 'Intermediate Python for Data Science/Case Study- Hacker Statistics/.ipynb_checkpoints/04-The next step-checkpoint.ipynb', 'repo_name': 'nazmusshakib121/Python-Programming', 'size': '1610'}