Python Forum
Need help with lists to continue my assignment code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Need help with lists to continue my assignment code (/thread-372.html)



Need help with lists to continue my assignment code - tinabina22 - Oct-07-2016

How can I add a name and password to my list named, "samplePasswordFile" using Python 3.
I need to do this:
if(choice == '3'):
    print("What website is this password for?")
    website = input()
    print("What is the password?")
    unencryptedPassword = input()
Using this information:
encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
  • the encryptionKey variable is defined already as 16, don't change this

  • create a list of size 2, first item the website name and the second item the password.

  • append the list from Step 2 to the password list



RE: Need help to continue my assignment code - wavic - Oct-07-2016

Which module you are using? What does
passwordEncrypt(unencryptedPassword,encryptionKey)
return


RE: Need help to continue my assignment code - tinabina22 - Oct-07-2016

I'm using Python 3.5, Pycharm.


This is what the instructions: Wrote:####### YOUR CODE HERE ######
#You will need to encrypt the password and store it in the list of passwords

#The encryption function is already written for you
#Step 1: You can say encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)]
#the encryptionKey variable is defined already as 16, don't change this
#Step 2: create a list of size 2, first item the website name and the second item the password.
#Step 3: append the list from Step 2 to the password list

This is what I have so far:
input = samplePasswordFile.append([website, encryptedPassword])
This is the error code I am getting with it:
Error:
input = samplePasswordFile.append([website, encryptedPassword]) NameError: name 'samplePasswordFile' is not defined
The code won't even read beyond that, so have no idea what:
encryptedPassword = passwordEncrypt(unencryptedPassword,encryptionKey)
Is going to result in.


RE: Need help to continue my assignment code - wavic - Oct-07-2016

If samplePasswordFile is the name of the list you have to define it before use it.
samplePasswordFile = []
This creates an empty list with name samplePasswordFile. Then you can append a variables to that list.
samplePasswordFile.append(variable)
Do it once to append the site url and second time to append the encrypted password.

You better look at http://python-forum.io/Thread-List-basic


RE: Need help to continue my assignment code - Yoriz - Oct-08-2016

(Oct-07-2016, 11:05 PM)wavic Wrote: Do it once to append the site url and second time to append the encrypted password.

That would not end up with a list of lists that contains lists of 2 items, the website and the password
That would create a list like this
Output:
['website1', 'encryptedpassword1', 'website2', 'encryptedpassword2']
The list should end up looking like
Output:
[['website1', 'encryptedpassword1'], ['website2', 'encryptedpassword2']]
(Oct-07-2016, 10:53 PM)tinabina22 Wrote:
input = samplePasswordFile.append([website, encryptedPassword])
This is the error code I am getting with it:
Error:
input = samplePasswordFile.append([website, encryptedPassword]) NameError: name 'samplePasswordFile' is not defined
The error is because samplePasswordFile is not defined as pointed out by wavic, so define it like wavic showed
samplePasswordFile = []
when it does
samplePasswordFile.append([website, encryptedPassword])
the result does not need storing in input (which is a built in function so don't use it as a variable name) because it directly alters samplePasswordFile instead of returning an altered list.


RE: Need help with lists to continue my assignment code - wavic - Oct-08-2016

Hmm! I got it wrong apparently. I was thinking the square bracket is mistype. The end of his second code example


RE: Need help with lists to continue my assignment code - tinabina22 - Oct-11-2016

I'm sorry that my code is a mess, but only the very last few lines are mine, the rest is from our instructor. But you can delete it I figured it out.


RE: Need help with lists to continue my assignment code - metulburr - Oct-11-2016

Quote:I'm sorry that my code is a mess, but only the very last few lines are mine, the rest is from our instructor. But you can delete it I figured it out.
That was regarding an unrelated post i moved to a different thread. Can you post your solution?


RE: Need help with lists to continue my assignment code - tinabina22 - Oct-12-2016

Here is the solution for #3, although now #5 is not working!  
if (choice == '3'):
   print( "What website is this password for?" )
   website = input( )
   print( "What is the password?" )
   unencryptedPassword = input( )


   def encrypted_password():
       encrypted_password = passwordEncrypt( unencryptedPassword, encryptionKey )
       samplePasswordFile = [[website, encrypted_password]]
       passwords.append( [website, encrypted_password] )


if (choice == '5'):  # print out the password list
   for keyvalue in passwords:
       print( ', '.join( keyvalue ) )



RE: Need help with lists to continue my assignment code - Yoriz - Oct-12-2016

Not working is not enough information when asking for help.
Do you get a traceback error that you can show us.
What are you expecting to happen against what is actually happening.