【发布时间】:2016-09-05 12:30:02
【问题描述】:
我正在制作一个程序,该程序应该对您传入的密码进行加密。但是,每当我运行它时,它都会引发错误:
Password = float(input('Enter Password: '))
ValueError: could not convert string to float: 'Banana'(我为这个测试选择的词)
这是我的代码:
#Macchiat0
#10 May 2016
#This program will encrypt and decrypt user passwords.
#init
encryptionlist = (('a','q'),
('b','w'),
('c','e'),
('d','r'),
('e','t'),
('f','y'),
('g','u'),
('h','i'),
('i','o'),
('j','p'),
('k','a'),
('l','s'),
('m','d'),
('n','f'),
('o','g'),
('p','h'),
('q','j'),
('r','k'),
('s','l'),
('t','z'),
('u','x'),
('v','c'),
('w','v'),
('x','b'),
('y','n'),
('z','m'))
print('This program will encrypt and decrypt user passwords')
#Program Menu
ans = True
while True:
print('1. Enter 1 to encrypt a password: ')
print('2. Enter 2 to decrypt a password: ')
print('3. Exit/Quit')
ans = input('What do you want to do? ')
if ans == "1":
print("\n Enter 1 to encrypt a password: ")
Password = float(input('Enter Password: '))
print('Your new encryptid password is:', Password)
if ans == "2":
print("\n Enter 2 to decrypt a password: ")
Password = float(input('Enter Password: '))
print('Your new decrypted password is:', Password)
elif ans == "3":
print("\n Goodbye")
break
else:
print("\n Not Valid Choice Try Again")
【问题讨论】:
-
错误很明显:
ValueError: could not convert string to float: 'Banana'You can't convertBananato a float.. -
答案直接来自错误信息,'banana' 不是数字。你为什么在
Password = float(input('Enter Password: '))中使用float -
另外,能够解密用户密码是非常错误的。但如果是为了好玩,那也没关系。至于您的问题,正如其他人所说,您需要删除 'float(...)' 。
-
这只是我个人的学习项目之一。我不打算对此进行任何非法活动
-
人们并不担心你会做任何违法的事情。他们担心你会实施这个并认为它是“安全的”或“安全的”。
标签: python encryption password-storage