+ 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=",")
2 Antworten
+ 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..
+ 2
Thanks alot I've seen the mistakes