我只做了一个因数查询器(1~100),可出现了语法错误,不知道怎么回事,麻烦看一下吧

checknunber=input(print('您想查哪个数字'))  #查询的数字输入
print('查询中')                         #为了美观
contnunber==100                        #因数个数提供给后面吧不是引述的部分剪掉
for contnunber range(1,100):
    if contnunber%7==0:                #如果contnunber变量和7
    continue
    else                              #如果余数不是0,将这个数从contnunber变量中删除
    contnunber-=1
print("有"+contnunber)                #输出
最佳答案

我给你一个世界上所有因数的查询器就行了,别费劲了

def factor(x):

num = 1

while num <= x:

    if x % num == 0:

        print(num,end='')

        print(' ',end='')

        num = num + 1

x = int (input ("输入数字:"))

factor(x)

choice=input ('\n 继续输入 1,推出输入其他 ')

while choice=='1':

x = int(input("输入数字:"))

factor(x)

choice=input('\n继续输入1,推出输入其他')
5年前 评论
Coolest 5年前
Lele1357 (作者) 5年前
acup (楼主) 5年前
Lele1357 (作者) 5年前
acup (楼主) 5年前
讨论数量: 9

你这代码。。。。。。好几处错误

5年前 评论
checknunber=input(print('您想查哪个数字'))#第一处错误
print('查询中')              
contnunber==100          #第二处错误
for contnunber range(1,100):#第七处错误
    if contnunber%7==0:            
    continue             #第三处错误
    else                 #第四处错误
    contnunber-=1        #第五处错误
print("有"+contnunber) #第六处错误

第一处错误:虽然不会报错,但是 input () 函数已经自带了打印效果,不需要加 print 否则会无缘无故打印个 None

第二处错误:= 是赋值的意思,而 == 是用来判断两个值相不相同,就像 1 == 2,就会返回 False,因为 1 不等于 2

第三处错误:在 if 真的执行体中,所有代码都要缩进,一个缩进 = 4 个空格

第四处错误:else 要加 “:”

第五处错误:在 else 的执行体中,所有代码都要缩进,一个缩进 = 4 个空格

第六处错误:“有” 是字符串,contnunber 是数字,字符串和数字不能拼接。

第七处错误:for coutnunber range (1,100) 要加上 in。

第八处错误:你 coutnunber 拼错了,是 countnumber,学学英语吧,兄弟:joy:
正确的代码:

checknunber=input('您想查哪个数字')  #查询的数字输入
print('查询中')                         #为了美观
contnunber=100                        #因数个数提供给后面吧不是引述的部分剪掉
for contnunber in range(1,100):
    if countnunber%7==0:                #如果countnunber变量和7
        continue
    else:                           #如果余数不是0,将这个数从contnunber变量中删除
        countnumber-=1
print("有"+str(countnumber))
5年前 评论
Coolest (作者) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
Coolest (作者) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
Coolest (作者) 5年前
Coolest (作者) 5年前
acup (楼主) 5年前
Coolest (作者) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
Coolest (作者) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
acup (楼主) 5年前
Coolest (作者) 5年前
Coolest (作者) 5年前
Coolest (作者) 5年前
Jason990420
1. input(print('您想查哪个数字')) => input('您想查哪个数字')
2. for contnunber range(1,100): => for contnunber in range(1,100):
3. continue, contnunber-=1没缩格
4. print("有"+contnunber)  字符串和整数不能相加
5. 逻辑错误就不提了

错的地方太多了,直接改了

check_number=int(input(print('您想查哪个数字')))
print('查询中')
result = []
for number in range(2, check_number):
    if check_number%number == 0:
        result.append(str(number))
if len(result)==0:
    print('除了1和本身, 没有因数 !!')
else:
    print(f'{check_number}因数有{", ".join(result)}')
5年前 评论
acup (楼主) 5年前
acup (楼主) 5年前
Jason990420 (作者) 5年前
Coolest 5年前
checknunber=int(input('您想查哪个数字')) #查询的数字输入
print('查询中')                         #为了美观
countnunber=100                        #因数个数提供给后面吧不是引述的部分剪掉
for countnunber in range(1,100):
    if countnunber%7==0:                #如果countnunber变量和7
        continue
    else:                           #如果余数不是0,将这个数从contnunber变量中删除
        countnumber-=1
print("有"+str(countnumber))
5年前 评论

checknumber=int (input (' 您想查哪个数字 ')) #查询的数字输入 print (' 查询中 ') #为了美观 countnumber=100 #因数个数提供给后面吧不是引述的部分剪掉 for countnumber in range (1,100): if countnumber% checknumber==0: #如果 countnunber 变量和 7 continue else: #如果余数不是 0,将这个数从 contnunber 变量中删除 countnumber-=1 print ("有"+str (countnumber))

5年前 评论
Coolest 5年前
Coolest 5年前
Jason990420
check_number=int(input(print('您想查哪个数字')))
print('查询中')
result = []
for number in range(2, 100):
    if check_number%number == 0:
        result.append(str(number))
if len(result)==0:
    print('除了1和本身, 没有因数 !!')
else:
    print(f'{check_number}因数在100以下有{", ".join(result)}')
5年前 评论

学习中基础很重要, 我也在继续看文档中。

5年前 评论
Coolest 5年前

我给你一个世界上所有因数的查询器就行了,别费劲了

def factor(x):

num = 1

while num <= x:

    if x % num == 0:

        print(num,end='')

        print(' ',end='')

        num = num + 1

x = int (input ("输入数字:"))

factor(x)

choice=input ('\n 继续输入 1,推出输入其他 ')

while choice=='1':

x = int(input("输入数字:"))

factor(x)

choice=input('\n继续输入1,推出输入其他')
5年前 评论
Coolest 5年前
Lele1357 (作者) 5年前
acup (楼主) 5年前
Lele1357 (作者) 5年前
acup (楼主) 5年前