【问题标题】:TypeError: can only concatenate str (not "int") to str debugTypeError:只能将str(不是“int”)连接到str debug
【发布时间】:2021-06-23 23:36:22
【问题描述】:

顺便说一句,我是堆栈溢出的新手

我正在 python 中创建一个 ATM,但它会永远运行。但是我遇到了代码问题。错误说: TypeError:只能将str(不是“int”)连接到str

这是我的代码(或者至少是它停止工作的部分):

def username_and_password2():
    balance_function = ''
    z = 0
    y = 1
    while True:
        e = input("What is your username: ")
        if e in security:
            b = input("What is the password: ")
            if security[e] == b:
                d = list(b)
                while True:
                    if d[z] == ':':
                        break
                    else:
                        z = z+1
                        continue
                while True:
                    if b[z] == ':':
                        break
                    else:
                        continue
                for i in range(z,len(b)):
                    balance_function = balance_function+str(d[z]+y)
                    y = y+1
                return balance_function
                print("Access granted\n")
                break
            else:
                print(security[e])
                print("Invalid password\n")
        else:
            print("Invalid username\n")

你能告诉我我哪里出错了吗?谢谢。

【问题讨论】:

  • 我建议还提到错误的完整堆栈跟踪。

标签: python


【解决方案1】:

错误发生在这里:

for i in range(z,len(b)):
    balance_function = balance_function+str(d[z]+y)

d[z]stringyint。你需要这样做:

balance_function = balance_function+str(d[z]+str(y))

【讨论】:

    猜你喜欢
    • 2021-02-15
    • 2020-09-18
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2021-02-06
    相关资源
    最近更新 更多