0

problem

how can i add the variable base to the loop in order to add 1 to it for each circle ? a=int(input("Primo numero")) #22 2*11 b=int(input("secondo numero")) divisori=[2,3,5,7,11,13,17] listaA=[] listaB=[] base=0 for a in range(0,a+1): if a%int(divisori[base])==int(0): listaA.append(divisori[base]) a=a/divisori[base] # 11 elif a%divisori[base]!=0: base+=1 print(listaA)

22nd Mar 2019, 5:04 PM
Francesco Zanella
Francesco Zanella - avatar
16 Respuestas
+ 4
It seems to work if you use numbers like 2 and 7. I don't really understand what you're trying to do though. Note that you have to enter all numbers in separate lines as soon as you run the code: 2<enter> 7
22nd Mar 2019, 6:19 PM
Anna
Anna - avatar
+ 4
I see. I made a couple of changes and it seems to work: a=int(input("Primo numero")) #22 2*11 #b=int(input("secondo numero")) divisori=[2,3,5,7,11,13,17] listaA=[] #listaB=[] #base=0 for base in range(0,len(divisori)-1): while a%divisori[base]==0: listaA.append(divisori[base]) a=a/divisori[base] # 11 base+=1 print(listaA) The main issue is that you need to use a while loop instead of an if clause
22nd Mar 2019, 6:44 PM
Anna
Anna - avatar
+ 4
You're welcome ☺️
22nd Mar 2019, 6:51 PM
Anna
Anna - avatar
+ 3
Francesco Zanella I've heard a lot about sites like codewars and project Euler, but I never tried them 😞
22nd Mar 2019, 8:45 PM
Anna
Anna - avatar
+ 2
for a in range(0,a+1): base += 1 No?
22nd Mar 2019, 5:59 PM
Anna
Anna - avatar
+ 2
It's defined right before the for loop No?
22nd Mar 2019, 6:13 PM
Anna
Anna - avatar
+ 2
It seems to work if you use numbers like 2 and 7. I don't really understand what you're trying to do though. Note that you have to enter all numbers in separate lines as soon as you run the code: 2<enter> 7
22nd Mar 2019, 6:20 PM
Anna
Anna - avatar
+ 1
Thanks for your patience
22nd Mar 2019, 6:51 PM
Francesco Zanella
Francesco Zanella - avatar
+ 1
Thanks a lot
22nd Mar 2019, 6:51 PM
Francesco Zanella
Francesco Zanella - avatar
22nd Mar 2019, 8:47 PM
Francesco Zanella
Francesco Zanella - avatar
0
No because is errore base is not defined
22nd Mar 2019, 6:10 PM
Francesco Zanella
Francesco Zanella - avatar
0
Try my code, it don't run
22nd Mar 2019, 6:14 PM
Francesco Zanella
Francesco Zanella - avatar
0
And I have defined base before the for loop
22nd Mar 2019, 6:14 PM
Francesco Zanella
Francesco Zanella - avatar
0
With base+=1 on elif
22nd Mar 2019, 6:15 PM
Francesco Zanella
Francesco Zanella - avatar
0
So, I willl explain you how it works. I want to the divisors of the given number. But it work only if a divisor is not repeated, for example with 22 it works because it find 2 and 11 as divisors because they are not repeated. But for example with 8 it doesnt work and it find only 2 repeated 1 time instead of 3
22nd Mar 2019, 6:28 PM
Francesco Zanella
Francesco Zanella - avatar
0
Another question can you give a site or something like that where I can find exercises beginner/intermediate for python
22nd Mar 2019, 7:35 PM
Francesco Zanella
Francesco Zanella - avatar