This is an assignment that is due next week and I'm stuck on the for i in range code at the bottom highlighted with purple font. I have included the instructions from my professor as well as the beginning of the code. It's a password saver code that we need to make work.
Beginning of code:
What I need to make work:
#1. Create a loop that goes through each item in the password list
# simplest way to loop through a list is: for i in range(len(NAMEOFLIST))
Beginning of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import csv import sys #The password list - We start with it populated for testing purposes passwords = [[ "yahoo" , "XqffoZeo" ],[ "google" , "CoIushujSetu" ]] #The password file name to store the passwords to passwordFileName = "samplePasswordFile" #The encryption key for the caesar cypher encryptionKey = 16 #Caesar Cypher Encryption def passwordEncrypt (unencryptedMessage, key): #We will start with an empty string as our encryptedMessage encryptedMessage = '' #For each symbol in the unencryptedMessage we will add an encrypted symbol into the encryptedMessage for symbol in unencryptedMessage: if symbol.isalpha(): num = ord (symbol) num + = key if symbol.isupper(): if num > ord ( 'Z' ): num - = 26 elif num < ord ( 'A' ): num + = 26 elif symbol.islower(): if num > ord ( 'z' ): num - = 26 elif num < ord ( 'a' ): num + = 26 encryptedMessage + = chr (num) else : encryptedMessage + = symbol return encryptedMessage def loadPasswordFile(fileName): with open (fileName, newline = '') as csvfile: passwordreader = csv.reader(csvfile) passwordList = list (passwordreader) return passwordList def savePasswordFile(passwordList, fileName): with open (fileName, 'w+' , newline = '') as csvfile: passwordwriter = csv.writer(csvfile) passwordwriter.writerows(passwordList) while True : print ( "What would you like to do:" ) print ( " 1. Open password file" ) print ( " 2. Lookup a password" ) print ( " 3. Add a password" ) print ( " 4. Save password file" ) print ( " 5. Print the encrypted password list (for testing)" ) print ( " 6. Quit program" ) print ( "Please enter a number (1-4)" ) choice = input () if (choice = = '1' ): #Load the password list from a file passwords = loadPasswordFile(passwordFileName) if (choice = = '2' ): #Lookup at password print ( "Which website do you want to lookup the password for?" ) for keyvalue in passwords: print (keyvalue[ 0 ]) passwordToLookup = input () |
1 2 |
for i in range ( len ( 'yahoo, google' )): print ( 'i' ) |
# simplest way to loop through a list is: for i in range(len(NAMEOFLIST))