Lesson 15 of 34

Loop Patterns: योग, गिनती और आकृतियाँ

10 min 35 XP

Pattern 1, accumulator: loop से पहले total = 0 रखें और हर चक्कर में उसमें जोड़ें।

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Pattern 2, counter: शर्त सही होने पर ही count में 1 जोड़ें।

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Pattern 3, आकृतियाँ: "*" * 3 से "***" बनता है। loop के साथ मिलाकर आकृतियाँ बनाएँ।

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

ये तीन patterns आ गए, तो कई coding इंटरव्यू सवाल आसान हो जाते हैं।

Challenge

+35 XP

n = 4 के साथ यह त्रिकोण print करें: * ** *** ****

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.