Random characters

Let’s create a program to choose a random character for your password.

  • Open the blank Python template Trinket: jumpto.cc/python-new.
  • Create a list of characters, stored in a variable called chars.

    screenshot

  • To choose a random character, you’ll need to import the random module.

    screenshot

  • Now you can choose a random character from the list, and store it in a variable called password.

    screenshot

  • Finally, you can print your (very short!) password to the screen.

    screenshot

  • Test your project by clicking ‘run’. You should see a single random character on the screen.

    screenshot

    If you run your program a few times, you should see different characters appear.

  • A password isn’t very secure if it only contains letters. Add some numbers to your chars variable.

    screenshot

  • Test your code again a few times, and you should see that sometimes a number is chosen.