Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将登录尝试次数增加到一定数量?_Python_Python 3.x - Fatal编程技术网

Python 如何将登录尝试次数增加到一定数量?

Python 如何将登录尝试次数增加到一定数量?,python,python-3.x,Python,Python 3.x,我正在开发一个程序,它打印一些技术人员的基本用户信息,然后通过调用“increment\u login\u attempts()”方法增加用户登录尝试次数。此方法允许用户登录3次或更少,但如果超过该值,则会声明elif语句“您尝试了太多时间,设备已锁定”。前面的方法“重置登录尝试次数”将登录尝试次数重置为0。我的问题是,当我用一个随机数的参数调用该方法时,它不会打印任何整数值。当我包含重置值时,它只打印0。任何帮助都会很好,谢谢 class User: def __init__(

我正在开发一个程序,它打印一些技术人员的基本用户信息,然后通过调用“increment\u login\u attempts()”方法增加用户登录尝试次数。此方法允许用户登录3次或更少,但如果超过该值,则会声明elif语句“您尝试了太多时间,设备已锁定”。前面的方法“重置登录尝试次数”将登录尝试次数重置为0。我的问题是,当我用一个随机数的参数调用该方法时,它不会打印任何整数值。当我包含重置值时,它只打印0。任何帮助都会很好,谢谢

    class User:
    def __init__(self, first_name, last_name, email, expertise):
        self.first_name = first_name
        self.last_name = last_name
        self.email = email
        self.expertise = expertise
        self.login_attempts = 0

    def describe_user(self):
        print("The current user's summary: " + self.first_name.title() +
              self.last_name.title() + ", " + self.email + "," + self.expertise)

    def greet_user(self):
        print("Hello " + self.first_name.title() + self.last_name.title())

    def increment_login_attempts(self, attempts):
        self.login_attempts = attempts

        if attempts >= self.increment_login_attempts:
            self.login_attempts = attempts

            if attempts <= 3:
                attempts += 1
                print self.login_attempts

            elif attempts > 3:
                print("You have tried too many times, device is locked.")

    def reset_login_attempts(self, attempts):
        self.login_attempts = 0
        print self.login_attempts

user1 = User("Aye", "Bee", "ab@gmail.com", "Computer Hardware")
user2 = User("Cee", "Dee", "cd@mozila.com", "Computer Networks")
user3 = User("Ee", "Eff", "ef@pillowz.com", "Operating Systems")

print("The Malware Analyst is " + user1.first_name.title() + ' ' + user1.last_name.title())
print("Her expertise is in " + user1.expertise)
print("Her email is " + user1.email) 
print("-------------------------------------")

print("The Security Engineer is " + user2.first_name.title() + ' ' + user2.last_name.title())
print("His expertise is in " + user2.expertise)
print("His email is " + user2.email)
print("-------------------------------------")

print("The Pen Tester is " + user3.first_name.title() + ' ' + user3.last_name.title()) 
print("His expertise is in " + user3.expertise)
print("His email is " + user3.email)

# What you are doing is incrementing the login attempts by using calling increment_login_attempts
user1.increment_login_attempts(33)
user1.reset_login_attempts(1)
类用户:
定义初始(自我、名字、姓氏、电子邮件、专业知识):
self.first\u name=first\u name
self.last\u name=last\u name
self.email=电子邮件
专业知识
self.login\u尝试次数=0
def描述用户(自身):
打印(“当前用户的摘要:+self.first_name.title()+
self.last_name.title()
def greet_用户(自身):
打印(“你好”+self.first\u name.title()+self.last\u name.title())
def增量\登录\尝试次数(自我,尝试次数):
self.login\u尝试次数=尝试次数
如果尝试次数>=self.increment\u登录\u尝试次数:
self.login\u尝试次数=尝试次数
如果尝试3:
打印(“您尝试了太多次,设备已锁定。”)
def重置\登录\尝试(自我,尝试):
self.login\u尝试次数=0
打印self.login\u尝试
user1=用户(“是”,“蜜蜂”,“蜜蜂”ab@gmail.com“,“计算机硬件”)
user2=用户(“Cee”、“Dee”cd@mozila.com“,“计算机网络”)
user3=用户(“Ee”,“Eff”,”ef@pillowz.com“,“操作系统”)
打印(“恶意软件分析师是”+user1.first\u name.title()+“”+user1.last\u name.title())
打印(“她的专长是”+user1.experties)
打印(“她的电子邮件是”+user1.email)
打印(“---------------------------------------”)
打印(“安全工程师是”+user2.first\u name.title()+“”+user2.last\u name.title())
打印(“他的专业技能是”+user2.experties)
打印(“他的电子邮件是”+user2.email)
打印(“---------------------------------------”)
打印(“笔测试仪为“+user3.first_name.title()+”+user3.last_name.title())
打印(“他的专业知识在”+user3.专业知识中)
打印(“他的电子邮件是”+user3.email)
#您所做的是通过调用increment\u login\u尝试来增加登录尝试
user1.递增登录尝试次数(33)
用户1.重置\登录\尝试次数(1)

如果尝试次数>=self.increment\u login\u尝试次数:
这与您认为的不一样:

如果
尝试次数
大于
self.increment\u login\u尝试次数
函数的内存位置

由于
尝试次数
是33次,并且
self.increment\u login\u尝试次数
的内存地址是一个很大的数字,因此它跳过了函数的其余部分

def increment_login_attempts(self, attempts=None):

    if attempts:
        self.login_attempts = attempts
    else:
        self.login_attempts += 1

    if self.login_attempts <= 3:
        print self.login_attempts
    else:
        print("You have tried too many times, device is locked.")
def增量登录尝试次数(self,尝试次数=None):
如果尝试:
self.login\u尝试次数=尝试次数
其他:
self.login_尝试次数+=1

如果self.login\u尝试
如果尝试>=self.increment\u login\u尝试:
这与您认为的不一样:如果
尝试
大于
self.increment\u login\u尝试
函数的内存位置。。。