40923250 cp2020

  • Home
    • Site Map
    • reveal
    • blog
  • First
  • Hw1
    • PCH18
      • Laptop and Notebook Component Replacement
      • Troubleshooting Hard Drives
    • PCH19
      • Overview
      • AC Power
      • Proper Disposal Procedures
      • Security
  • HW2
    • 2-1 取得一甲分組數列
    • 2-2 是否有人加退選
    • 2-3 產生W3網頁html
  • Hw3
    • 14.移除重複項
    • 15.倒序
    • 16.密碼生成器
  • 學習日記
    • git clone
    • 刪除submodule
    • ORError
    • ssh keygen
  • python
    • Variables 變數
15.倒序 << Previous Next >> 學習日記

16.密碼生成器

Password Generator    

Exercise 16 (and Solution)

Write a password generator in Python. Be creative with how you generate passwords - strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols. The passwords should be random, generating a new password every time the user asks for a new password. Include your run-time code in a main method.

Extra:

  • Ask the user how strong they want their password to be. For weak passwords, pick a word or two from a list.

Discussion

There are no new topics this week, but you will need to use Python’s random module, described in this post.

Ans.

#導入隨機
import random
#設一字串當做隨機樣本
s = "0123456789ABCDEFGHIJKLMNPQRTUVWXYZabcdefghijklmnpqrtuvwxyz"
#設一int當作密碼長度
passlen = 8
#設一空字串,並加入隨機樣本和樣本數
P = "".join(random.sample(s,passlen))
print(P)


15.倒序 << Previous Next >> 學習日記

Copyright © All rights reserved | This template is made with by Colorlib