Nov-16-2020, 12:23 PM
Hi all I'm studying python recently and I'm newbie on programming language also
I'm writing a pyhthon code that print two different sequence number, the first one composed with 1,2,3,4,..n the second one with 1,5,9.13,.m
So I'd like to obtain an output like this:
1 1
2 5
3 9
4 13
5 17
....
I've tried with the following "for loop nested" but the result is not what I'm looking for
1 1
1 5
1 9
2 5
2 9
3 5
3 9
4 5
4 9
5 5
5 9
6 9
7 9
8 9
9 9
So..Have you got any suggestion for modify this code to get the correct output?
Anyway is the "for loop nested" the right way or there is another way?
Thanks
Riccardo
I'm writing a pyhthon code that print two different sequence number, the first one composed with 1,2,3,4,..n the second one with 1,5,9.13,.m
So I'd like to obtain an output like this:
1 1
2 5
3 9
4 13
5 17
....
I've tried with the following "for loop nested" but the result is not what I'm looking for
numeri1 = range(1,10) numeri2 = range(1,10,4) for elemento_1 in numeri1: for elemento_2 in numeri2: if elemento_1 <= elemento_2: print (elemento_1, elemento_2)Infact the output obtained using this code is the following
1 1
1 5
1 9
2 5
2 9
3 5
3 9
4 5
4 9
5 5
5 9
6 9
7 9
8 9
9 9
So..Have you got any suggestion for modify this code to get the correct output?
Anyway is the "for loop nested" the right way or there is another way?
Thanks
Riccardo