#Passwordgen
#Generate a password
def main():
#Ask the user to input a long string of words, separated by spaces
sent = input("Enter a sentance separated by spaces: ")
#Ask the user to input a position within each word
#Take the position of that word
pos = eval(input("Input a position within each word: "))
words = sent.split(" ")
wordy = ""
#loops through the word to take the position of the letter
for word in words:
wordy = wordy + word[pos]
#Prints out the letters as a password
print("Your password is: ", wordy)
main()
我的教授希望我輸出從零開始,從零開始到包括用戶輸入的位置在內的每個位置生成的密碼。它應該使用密碼(短語,位置)函數來生成密碼。使用python函數調整代碼
使用字符串格式打印每個密碼輸出行,如下所示。
例如:
Enter words, separated by spaces: correct horse battery staple
Up to position within each word: 3
Password 0: chbs
Password 1: ooat
Password 2: rrta
Password 3: rstp
你的問題是什麼?我只看到一個項目描述。另外,你爲什麼使用'eval'? – Carcigenicate
這太寬了。你已經嘗試了什麼?你需要什麼特別的幫助?回答目前狀態下的這個問題只是爲你做功課。如果您有關於您已經嘗試過的具體問題,我們可以爲您提供幫助。 – Carcigenicate