हिंदी

Find the output of the following program segment: i = 0; sum = 0 while i < 9: if i % 4 == 0: sum = sum + i i = i + 2 print (sum) - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Find the output of the following program segment:

i = 0; sum = 0
while i < 9:
        if i % 4 == 0:
               sum = sum + i
        i = i + 2
print (sum)
टिप्पणी लिखिए
Advertisements

उत्तर

The ‘while’ loop will run till the value of 'i' is 8, and the condition in the ‘if’ function will return true for two values i.e. 4 and 8, which will be added to ‘sum’. The last statement will print the value of the variable ‘sum’.

OUTPUT:
12

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Flow of Control - Exercise [पृष्ठ १४०]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
अध्याय 6 Flow of Control
Exercise | Q 5. (iv) | पृष्ठ १४०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×