首页 > 解决方案 > TypeError:'int'对象不可调用python3但没有round()或sum()函数

问题描述

目前正在尝试创建一个程序,该程序在给定用户输入的位数的情况下生成一个数字,但是,它有时会在用户的数字选择下生成。我创建了一个 if 条件来检查这一点,但它给了我以下错误:

TypeError: 'int' object is not callable

到目前为止,这是我的python3代码......

    # To generate number with certain amount of digits by user input as a list:
import random as gen
digit_count = int(input('Enter number of digits: '))
def function():
    max = int('9' * digit_count)
    number = gen.randint(0, max)
    check = len(str(abs(number)))
    if check != digit_count:
        print(number)
        function()
    else:
        print(number)
        print(max)
function()

标签: pythonpython-3.xfunction

解决方案


推荐阅读