Please what is wrong with the range | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Please what is wrong with the range

Why does it give me error def factors(a): list=[] for num in range(a+1) if a % num == 0: list.append (num) return list a = input('Enter a number: ') print(factors(a)) for num in factors(a) print(num) print(num,end=",")

10th May 2022, 4:58 PM
Bi Mi
Bi Mi - avatar
2 Answers
+ 2
def factors(a): list=[] for num in range(a+1) #missing : here, and also you must start from 1 so use range(1, a+1) otherwise a%0 raise error. if a % num == 0: list.append (num) return list #ident this out of loop else it only return 1 element of list a = input('Enter a number: ') #input defaultly is of string type, convert input to int type print(factors(a)) for num in factors(a) # missing : here print(num) # why this? print(num,end=",") # read comments, hope those helps to correct program..
10th May 2022, 5:09 PM
Jayakrishna 🇮🇳
+ 2
Thanks alot I've seen the mistakes
10th May 2022, 5:11 PM
Bi Mi
Bi Mi - avatar