原題:設計一個驗證用戶密碼程序,用戶只有三次機會輸入錯誤密碼,不過如果用戶輸入的內容包含“*”則不計算在內
改:設計一個驗證用戶密碼程序,用戶只有三次機會輸入錯誤密碼,如果用戶輸入的內容中包含*,則忽略
#!/usr/bin/env python
# -*- coding:utf-8 -*-
def word_change(list,str):
for x in str:
list.append(x)
key=[]
key1 = 'xingcheng1314'
word_change(key,key1)
pass1=[]
j=0
while j<3:
password = input("please enter your password:")
word_change(pass1,password)
if '*' in pass1:
pass1.remove('*')
i=0
while i<len(key) and i<len(pass1):
if key[i] == pass1[i]:
i += 1
else:
break
if i == len(key):
print('密碼正確歡迎光臨')
break
else:
print('密碼錯誤!')
j += 1
2.編寫一個程序,求100~999之間的所有水仙花數。
如果一個 3 位數等於其各位數字的立方和,則稱這個數爲水仙花數。例如:153 = 1^3 + 5^3 + 3^3,因此 153 就是一個水仙花數。
#!/usr/bin/env python
# -*- coding:utf-8 -*-
for x in range(100,1000):
bai = x//100
shi = (x-bai*100)//10
ge = x-bai*100-shi*10
if x == (bai**3 + shi**3 + ge**3):
print(x)
3.
2.三色球問題
有紅、黃、藍三種顏色的求,其中紅球 3 個,黃球 3 個,綠球 6 個。先將這 12 個球混合放在一個盒子中,從中任意摸出 8 個球,編程計算摸出球的各種顏色搭配
#!/usr/bin/env python
# -*- coding:utf-8 -*-
print("red" + "\tyellow" + "\tgreen")
for red in range(4):
for yellow in range(4):
for green in range(7):
if red + yellow + green == 8:
print(red,"\t\t",yellow,"\t\t",green)
0. 請寫一個密碼安全性檢查的腳本代碼:check.py
- # 密碼安全性檢查代碼
- #
- # 低級密碼要求:
- # 1. 密碼由單純的數字或字母組成
- # 2. 密碼長度小於等於8位
- #
- # 中級密碼要求:
- # 1. 密碼必須由數字、字母或特殊字符(僅限:~!@#$%^&*()_=-/,.?<>;:[]{}|\)任意兩種組合
- # 2. 密碼長度不能低於8位
- #
- # 高級密碼要求:
- # 1. 密碼必須由數字、字母及特殊字符(僅限:~!@#$%^&*()_=-/,.?<>;:[]{}|\)三種組合
- # 2. 密碼只能由字母開頭
- # 3. 密碼長度不能低於16位
#!/usr/bin/env python
# -*- coding:utf-8 -*-
condition1 = '0123456789'
condition2 = 'abcdefghilklmnopqrstuvwxyzABCDEFGHILKLMNOPQRSTUVWXYZ'
condition3 = r'~!@#$%^&*()_=-/,.<>;:[]{}|\?'
"""判斷輸入是否爲空或空格"""
password = input("please enter your password:")
length = len(password)
while length == 0 or password.isspace():
length = input("請重新輸入密碼")
"""長度檢測"""
length_check = 0
if length <= 8:
length_check = 1
elif 8 < length < 16:
length_check = 2
else:
length_check = 3
"""字符檢測"""
str_check = 0
for each in password:
if each in condition1:
str_check += 1
break
for each1 in password:
if each1 in condition2:
str_check += 1
break
for each2 in password:
if each2 in condition3:
str_check += 1
break
"""判定及輸出密碼強度"""
if length_check == 1 or str_check == 1:
print("低密碼")
elif length_check == 2 or str_check == 2:
print( "中密碼")
elif length_check == 3 and str_check == 3:
print( '高密碼')
else:
print("哈哈哈大傻逼")