【问题标题】:why here Twice run program为什么在这里两次运行程序
【发布时间】:2018-09-12 17:59:49
【问题描述】:
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()

为什么在这里两次运行 pas1 。我想运行一次def pas1(),然后转到下一行。这里两次问我how many do you have information ? 和两次ask me enter :

【问题讨论】:

  • 请更清楚您需要什么帮助以及什么是nnk??

标签: python python-3.x open-source


【解决方案1】:

代码问题:

密码类的对象创建不正确。 参数 self 也没有传递给类方法。

固定代码

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()

输出

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']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    相关资源
    最近更新 更多