Python 获得';非类型';对象没有属性';isdigit'&引用;我的代码出错

Python 获得';非类型';对象没有属性';isdigit'&引用;我的代码出错,python,python-3.8,Python,Python 3.8,我试图完成的代码是,我要求用户输入一个介于1和12之间的数字,然后显示该数字的时间表。 while循环检查它是否不是一个数字,或者它是否小于1或大于12,然后它将循环,直到输入正确为止。但是我得到了错误(写在标题上) 有没有办法解决这个问题 user_input = print('Input number between 1-12: ') #While loop to keep checking the following conditions while (not user_input.

我试图完成的代码是,我要求用户输入一个介于1和12之间的数字,然后显示该数字的时间表。 while循环检查它是否不是一个数字,或者它是否小于1或大于12,然后它将循环,直到输入正确为止。但是我得到了错误(写在标题上) 有没有办法解决这个问题

user_input = print('Input number between 1-12: ')


#While loop to keep checking the following conditions
while (not user_input.isdigit()) or (int(user_input < 1) or int(user_input > 12)):
  print("Please input a number between 1-12")
  user_input = print("Input selection >>  ")

#Now convert user_input into an int
user_input = int(user_input)
print('------------------------------------------')
print()
print(f'This is the {user_input} times table')
print()
for i in range(1,13):
  print(f'{i} x {user_input} = {i*user_input}')
用户输入=打印('1-12之间的输入编号:')
#While循环以继续检查以下条件
而(不是user_input.isdigit())或(int(user_input<1)或int(user_input>12)):
打印(“请输入1-12之间的数字”)
用户输入=打印(“输入选择>>”)
#现在将用户输入转换为整数
用户输入=int(用户输入)
打印('--------------------------------------')
打印()
打印(f'这是{user_input}时间表')
打印()
对于范围(1,13)内的i:
打印(f'{i}x{user\u input}={i*user\u input}')
上述行仅打印出
输入1-12之间的数字:
,并没有要求用户输入任何内容。由于
print()
函数显示其中的字符串并返回
None
,因此您会得到所得到的错误

如果要获取用户输入,请使用
input()
函数,如

user_input = input("Input number between 1-12: ")
上行将提示用户输入内容,同时也显示文本

user\u input=input('input number介于1-12之间:')
user_input = input('Input number between 1-12: ')


#While loop to keep checking the following conditions
while (not user_input.isdigit()) or (int(user_input)< 1 or int(user_input) > 12):
#While循环以继续检查以下条件 而(不是用户输入.isdigit())或(int(用户输入)<1或int(用户输入)>12):
问题清单:

  • 您打印而不是
    input
    ,以接收用户的输入

  • 您试图使用
    这是否回答了您的问题?我的错是,我看了好几次代码,没有看到打印,而是输入问题。我的错。谢谢你的回答!我没有看到打印,而是输入问题。我真傻。谢谢你回答我的问题!
    
    user_input = input('Input number between 1-12: ')
    
    
    #While loop to keep checking the following conditions
    while (not user_input.isdigit()) or (int(user_input)< 1 or int(user_input) > 12):