我的代码中的所有内容都看起来不错吗?

时间:2017-11-05 01:17:12

标签: python python-3.x

我可以改进什么?我是一个蟒蛇初学者。有什么我可以做的,使我的代码看起来更干净或只是让它看起来更专业?感谢

while True:
    print('What password will you be storing?')
    PassChoice = input()
    print('What is your username or email for this account?')
    UserOrEmail = input()
    print("What is the password for " + str(PassChoice) + '?')
    Password = input()
    print('Your password for ' + str(PassChoice) + ' has been stored.')
    WebsiteAndPassword = (str(PassChoice) + '| ' + str(UserOrEmail) +': ' + 
str(Password) + '\n')
    break

PasswordFile = open('importantpasswords.txt', 'a')
PasswordFile.write(str(WebsiteAndPassword))
PasswordFile.close()

2 个答案:

答案 0 :(得分:2)

请注意,此网站不适用于代码审核,但由于您是新手,因此有一些非常明显的内容:

    PassChoice = input('What password will you be storing?')
    UserOrEmail = input('What is your username or email for this account?')
    Password = input('What is the password for ' + PassChoice + '?')

如果要询问用户输入,可以将字符串作为输入函数的参数。此外,您不必将PassChoice强制转换为字符串,因为它是input()返回的类型。

答案 1 :(得分:0)

就个人而言,我会在获取用户密码时使用getpass https://docs.python.org/3/library/getpass.html库,您也可以通过以下方式简化它:

passChoice = input("What password will you be storing?")

或使用getpass:

import getpass

getpass.getpass(prompt="What password will you be storing?")