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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,693 questions

57,001 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 284 views
2 answers 284 views
1 answer 263 views
3 answers 367 views
...