Search code examples
pythonpython-3.xopen-source

why here Twice run program


class password:
    def pas1():
        pas = []
        tedad = int(input('how many do you have information ? '))

        for i in range(1,tedad):
            b=input('enter : ')
            pas.append(b)

        print('this is your pas ---> {}' . format(pas))

import nnk
me=nnk.password.pas1()

why here Twice run pas1 . i want once run def pas1() and next go to next line . here twice ask me how many do you have information ? and twice ask me enter :


Solution

  • Issues with Code :

    Object creation is not correct for password class. also argument self is not passed to class method .

    Fixed Code

    class password:
    
        def pas1(self):
            pas = []
            tedad = int(input('how many do you have information ? :  '))
    
            for i in range(1,tedad):
                b=input('enter : ')
                pas.append(b)
    
            print('this is your pas ---> {}' . format(pas))
    
    
    me=password()
    me.pas1()
    

    Output

    how many do you have information ? :  12
    enter : 2
    enter : 2
    enter : 3
    enter : 4
    enter : 5
    enter : 6
    enter : 6
    enter : 7
    enter : 8
    enter : 9
    enter : 4
    this is your pas ---> ['2', '2', '3', '4', '5', '6', '6', '7', '8', '9', '4']