Sum the Digits of a Number
Sum the Digits of a Number को संपादित और ऑनलाइन चलाए जा सकने वाले व्यावहारिक उदाहरण से सीखें।
Sum the Digits of a Number क्या है?
Sum the Digits of a Number को संपादित और ऑनलाइन चलाए जा सकने वाले व्यावहारिक उदाहरण से सीखें।
इसका उपयोग कब करें?
- चलने योग्य code से Python syntax सीखें।
- बड़ी programming समस्याओं से पहले मजबूत आधार बनाएँ।
- स्थानीय setup के बिना किसी विचार को तुरंत जाँचें।
उदाहरण कोड
main.py
number = 12345
# Convert each digit character back to an integer.
total = sum(int(digit) for digit in str(abs(number)))
print(f"sum={total}")
अपेक्षित आउटपुट
sum=15
यह कैसे काम करता है
यह उदाहरण Sum the Digits of a Number दिखाता है। कोड समझने के लिए इनपुट मान बदलें।
मान बदलें और Python इंस्टॉल किए बिना CodeUtility ऑनलाइन Python कंपाइलर में प्रोग्राम चलाएँ।
अभ्यास के कार्य
बड़े dataset पर जाने से पहले input बदलें और edge cases की जाँच करें।
- Code चलाने से पहले output का अनुमान लगाएँ।
- खाली और गलत input संभालें।
- Logic को function में रखें और tests जोड़ें।