Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to use nested for loops in Python

2 Answers

0 votes
for i in range(1, 4):
    j = 1
    print("i = ", i)
    for j in range(1, 6):
        print("... j = ", j)


'''
run:

i =  1
... j =  1
... j =  2
... j =  3
... j =  4
... j =  5
i =  2
... j =  1
... j =  2
... j =  3
... j =  4
... j =  5
i =  3
... j =  1
... j =  2
... j =  3
... j =  4
... j =  5

'''

 



answered May 8, 2017 by avibootz
0 votes
for x in range(1, 5):
    for y in range(1, 5):
        print('%d * %d = %d' % (x, y, x * y))


'''
run:

1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
3 * 4 = 12
4 * 1 = 4
4 * 2 = 8
4 * 3 = 12
4 * 4 = 16

'''

 



answered Oct 14, 2017 by avibootz

Related questions

1 answer 186 views
2 answers 155 views
1 answer 167 views
3 answers 215 views
...