def main():
user_number = float(input("Enter a number: "))
num = user_number//2
round(num,0)
int(num)
print(num)
divisor = 1
for divisor in range(divisor,num):
if num%divisor == 0:
print(divisor)
while True:
main()
我得到的语法错误:TypeError:'float'对象无法解释为整数
num = user_number // 2
的结果是浮点数。
调用round(num, 0)
不执行任何操作,因为您没有将结果存储在num
变量中。无论如何,结果是float
。您应该改写num = int(num)
。
您应该改写for divisor in range(divisor, int(num))
。