Python Forum
Need help with lists to continue my assignment code
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help with lists to continue my assignment code
#1
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
Reply
#2
Which module you are using? What does
passwordEncrypt(unencryptedPassword,encryptionKey)
return
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
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.
Reply
#4
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
(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.
Reply
#6
Hmm! I got it wrong apparently. I was thinking the square bracket is mistype. The end of his second code example
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
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.
Reply
#8
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?
Recommended Tutorials:
Reply
#9
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 ) )
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  morse code assignment raymond2688 11 8,501 Jul-29-2019, 07:43 PM
Last Post: raymond2688
  Write pseudo code for a class assignment Scrimshot 3 3,368 May-07-2019, 05:38 PM
Last Post: Scrimshot
  Need some help with a bit of code for an assignment. JackMercer50 1 2,267 Feb-09-2019, 04:13 PM
Last Post: stullis
  [split] Need help with lists to continue my assignment code cylandur 7 9,401 Oct-11-2016, 03:11 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020