Page 260 - CITS - CSA - TP (Volume 2) - Hindi
P. 260

कं  ूटर सॉ वेयर ए ीके शन  - CITS




           टा  2:   पाइथन म  While लूप का उपयोग करके  1 सीमा के  भीतर 5 या 7 से िवभा  सं ाओं को ि ंट करने के  िलए While लूप का उपयोग
           िकया जाता है
           कोड :
           # Take user input to set the limit for the loop
           limit = int(input(“Enter the Limit: “))

           # Initialize a variable i with the value 1
           i = 1

           # The loop will continue as long as i is less than the specified limit
           whilei< limit:
           # Check if the current value of i is divisible by 5 or 7

               ifi % 5 == 0 or i % 7 == 0:
           # Print the current value of i, followed by a space instead of a newline
           print(i, end=’ ‘)

           # Increment the value of i by 1 in each iteration
           i+=1
             ीकरण:

           •  limit = int(input(“Enter the Limit: “)): लूप के  िलए ऊपरी सीमा िनधा  रत करने के  िलए उपयोगकता  इनपुट लेता है। int() फ़ं  न का उपयोग
              इनपुट को पूणा क म  बदलने के  िलए िकया जाता है।
           •  i = 1: वे रएबल i को मान 1 से आरंभ करता है।

           •  whilei< limit:: while लूप तब तक जारी रहता है जब तक i िनिद   सीमा से कम है।
           •  if i % 5 == 0 or i % 7 == 0:: जाँचता है िक i का वत मान मान 5 या 7 से िवभा  है या नहीं। % ऑपरेटर िवभाजन के  बाद शेष की गणना करता
              है।
           •  print(i, end=’ ‘): यिद if कथन म  शत  स  है, तो यह i का वत मान मान ि ंट करता है, िजसके  बाद नई लाइन के  बजाय एक  ान होता है।

           •  i += 1: लूप के    ेक पुनरावृि  म  i का मान 1 से बढ़ाता है।
           लूप 1 से लेकर िनिद   सीमा तक सं ाओं के  मा म से पुनरावृित करता है, और   ेक सं ा के  िलए, यह जाँचता है िक  ा यह 5 या 7 से िवभा
           है। यिद शत  स  है, तो यह सं ा ि ंट करता है। लूप तब तक जारी रहता है जब तक i िनिद   सीमा तक नहीं प ँच जाता।
           आउटपुट:








           टा  3:   while लूप का उपयोग करके   थम n  ाकृ ितक सं ाओं के  वग  के  योग के  िलए  ो ाम िलख

           कोड :
           # Python program example to show the use of while loop
           # Take user input to set the limit for the loop

           n = int(input(“Enter the limit: “))
           # Initializing summation and a counter for iteration

           summation = 0
           c = 1

                                                           246

                                   CITS : IT & ITES - कं  ूटर सॉ वेयर अनु योग - अ ास 126
   255   256   257   258   259   260   261   262   263   264   265