The function main initializes a count variable to 5. It contains two nested for loops, the outer looping 3 times and the inner looping 2 times. Each iteration of both loops increments count by 1. When the function finishes and prints the count, it will be 10.
This PowerPoint helps students to consider the concept of infinity.
After execution of the main- what is the values of count- def main()-.docx
1. After execution of the main, what is the values of count?
def main():
count = 5
for i in range(3):
count = count + 1
for j in range(2):
count = count + 1
print('Count:', count)
[count]
Solution
Program :
def main(): // main function
count = 5 // Initially count is 5
for i in range(3): // The loop runs for i=1 through 3
count = count + 1 // Increment the count
for j in range(2): // The loop runs for j=1 through 2
count = count + 1 Â Â // Increment the count
print('Count:', count) Â Â // Display the count
2. [count]
Find count :
count = 5
For the first for loop :
for i in range(3):
count = count + 1
for i=1
count =6
for i=2
count =7
for i=3
count =8
So the count is 8.
For the second for loop :
now count=8
for j in range(2):
count = count + 1
for j=1
count=9
for j=2
count=10
Therefore the count is 10.
print('Count:', count)